JFreeChart中文显示乱码,英文正常的solution
2016-04-19 15:19
363 查看
低版本JFreeChart可以直接正常显示中文,而新版本的JFreeChart不再为显示中文提供方便,需要程序员自己进行设置字体,然后才可以显示中文,否则乱码,通常显示为方框。
显然,常规的解决思路就是自己设置字体。下面记录了常见设置:
折线图显示中文需要添加下列代码:
柱状图显示中文需要添加下列代码:
饼状图显示中文需要添加下列代码:
JFreeChart中文显示乱码还有更高级更统一的解决办法,详见http://blog.sina.com.cn/s/blog_67fdef900101ebgf.html
显然,常规的解决思路就是自己设置字体。下面记录了常见设置:
折线图显示中文需要添加下列代码:
Font titleFont=new Font("宋体", Font.ITALIC, 22); Font font=new Font("宋体",Font.BOLD,14); Font legendFont=new Font("隶书", Font.BOLD, 16); jfreechart.getTitle().setFont(titleFont); jfreechart.getLegend().setItemFont(legendFont); XYPlot plot=jfreechart.getXYPlot();<span style="white-space:pre"> </span>//或者有时可能是<span style="font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px;">CategoryPlot plot=jfreechart.getCategoryPlot(); </span> plot.getDomainAxis().setLabelFont(font); plot.getDomainAxis().setTickLabelFont(font); plot.getRangeAxis().setLabelFont(font);
柱状图显示中文需要添加下列代码:
jfreechart.getTitle().setFont(new Font("宋体", Font.ITALIC, 22));//设置标题字体 jfreechart.getLegend().setItemFont(new Font("宋体", Font.BOLD, 16)); <span style="font-family: Arial, Helvetica, sans-serif;">//设置图例类别字体 </span> jfreechart.setBackgroundPaint(Color.WHITE); CategoryPlot categoryPlot=jfreechart.getCategoryPlot();//用于设置显示特性 categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setDomainGridlinePaint(Color.BLACK);//分类轴网格线条颜色 categoryPlot.setDomainGridlinesVisible(true); categoryPlot.setRangeGridlinePaint(Color.GREEN);//数据轴网格线条颜色 CategoryAxis domainAxis=categoryPlot.getDomainAxis(); //水平底部列表 domainAxis.setLabelFont(new Font("黑体",Font.BOLD,14)); //水平底部标题 domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,12)); //垂直标题 ValueAxis rangeAxis=categoryPlot.getRangeAxis();//获取柱状 rangeAxis.setLabelFont(new Font("黑体",Font.BOLD,15)); //设置柱状标题
饼状图显示中文需要添加下列代码:
Font titleFont=new Font("宋体", Font.ITALIC, 22); Font font=new Font("宋体",Font.BOLD,14); Font legendFont=new Font("隶书", Font.BOLD, 16); jfreechart.getTitle().setFont(titleFont); jfreechart.getLegend().setItemFont(legendFont); PiePlot plot=(PiePlot)jfreechart.getPlot(); plot.setLabelFont(font);
JFreeChart中文显示乱码还有更高级更统一的解决办法,详见http://blog.sina.com.cn/s/blog_67fdef900101ebgf.html
相关文章推荐
- JS调用OC简单实例-part1
- linux sighup 信号
- 关于网卡eth0、eth1以及服务器为什么要把内网和外网卡区分开
- java BufferedWriter and BufferedReader
- 进程间通信之信号量
- wpa_supplicant.conf文件详解
- Python webdriver 读取本地csv文件中数据 提示:IOError: [Errno 2] No such file or directory
- Linux命令--gzip,bzip2,tar,zip命令使用方法详解
- 面向对象在javascript中的三大特征之多态
- javase面试要点
- plsql显示中文乱码
- JS空值传到后台显示undefined
- linux ping
- CXF学习(4) 处理无法自动转换的复合数据类型
- Apple Watch 2.0 数据通讯
- 对于“ip欺骗”的预防
- AndroidUI之三分钟教你实现效果简单大气的Dialog提示框
- ulimit设置--最大文件打开数
- Problem A
- Problem A