JFreeChart中文乱码的解决方法
使用JFreeChart绘制图表的时候,如果使用默认的字体会导致图标中的汉字显示为乱码。解决方法如下:
JFreeChart是用户使用该库提供的各类图标的统一接口,JFreeChart主要由三个部分构成:title(标题),legend(图释),plot(图表主体)。三个部分设置字体的方法分别如下:
1.Title
view plaincopy to clipboardprint?
TextTitle textTitle = freeChart.getTitle();
textTitle.setFont(new Font("宋体",Font.BOLD,20));
TextTitle textTitle = freeChart.getTitle();
textTitle.setFont(new Font("宋体",Font.BOLD,20));
2.Legent
view plaincopy to clipboardprint?
LegendTitle legend = freeChart.getLegend();
if (legend!=null) {
legend.setItemFont(new Font("宋体", Font.BOLD, 20));}
LegendTitle legend = freeChart.getLegend();
if (legend!=null) {
legend.setItemFont(new Font("宋体", Font.BOLD, 20));}
3.Plot
对于不同类型的图表对应Plot的不同的实现类,设置字体的方法也不完全相同。
对于使用CategoryPlot的图表(如柱状图):
view plaincopy to clipboardprint?
CategoryPlot plot = (CategoryPlot)freeChart.getPlot();
CategoryAxis domainAxis = plot.getDomainAxis();//(柱状图的x轴)
domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴坐标上的字体
domainAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴上的标题的字体
ValueAxis valueAxis = plot.getRangeAxis();//(柱状图的y轴)
valueAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的字体
valueAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的标题的字体
CategoryPlot plot = (CategoryPlot)freeChart.getPlot();
CategoryAxis domainAxis = plot.getDomainAxis();//(柱状图的x轴)
domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴坐标上的字体
domainAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置x轴上的标题的字体
ValueAxis valueAxis = plot.getRangeAxis();//(柱状图的y轴)
valueAxis.setTickLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的字体
valueAxis.setLabelFont(new Font("宋体",Font.BOLD,20));//设置y轴坐标上的标题的字体
对于使用PiePlot的图标(如饼状图):
view plaincopy to clipboardprint?
PiePlot plot = (PiePlot)freeChart.getPlot();
plot.setLabelFont(new Font("宋体",Font.BOLD,15));
分享到:
相关推荐
JfreeChar学习资料 JfreeChar学习资料 JfreeChar学习资料
最新JFreeChar jar包 解决中文乱码 包含两个jar文件!
java开发的jfreechar插件,jfreechar报表开发工具插件
jfreehchar在LINUX下中文乱码的解决
jfreechar开发中应该如何配置,例子等
jfreechar饼图,超级实用
JfreeChar教程与实例。
java 做的动态实现JFreechar报表的例子,非常实用简单
使用JFreeChar,实现柱状图,饼形图,线性图
JFreeChar 柱图实现,教程,及其源码
jfreechar完整的例子,详细的解释,有web的,有main方法的
jfreechar各种图的样式...及代码
jfreechar 实现生成柱状图,饼图,曲线,没有调用正在的数据库数据,用的到的可以看看。
JFreeChar 动态曲线图,定时刷新,带节点事件
已经做好的项目, 部署上后可以直接运行,里有你想要的各种用jfreechar做的图标
资源有连个jfreechar 的例子,有饼图,还是条线图
JFreeChar制作饼图和柱状图 需要jcommon-1.0.0-rc1.jar包和jfreechart-1.0.0-rc1.jar包
包含所有的jfreechar画的饼状图、柱状图、曲线图所有代码都是本人自己编写并且能运行出结果的。
JfreeChar解析JfreeChar解析JfreeChar解析JfreeChar解析JfreeChar解析JfreeChar解析JfreeChar解析JfreeChar解析
JFreeChart它主要是用来制作各种各样的图表,这些图表包括:饼图、柱状图(普通柱状图以及堆栈柱状图)、线图、区域图、分布图、混合图、甘特图以及一些仪表盘等等。