jfreechart在LINUX下乱码问题的解决
在以下两个环境下测试成功:
环境1:CentOS4.4 + jdk1.6.0_26 + jfreechart-1.0.13 + jcommon-1.0.16
环境2:CentOS4.8 + jdk1.6.0_14 + jfreechart-1.0.13 + jcommon-1.0.16
在$JAVA_HOME/jre/lib/fonts/目录下创建名为fallback的子目录
将simsum.zip中的字体文件拷贝到此目录下
在jfreechart调用代码中添加如下方法,并调用此方法来设置字体:
private void setChartFont(JFreeChart jfreechart) { Font font = new Font("宋体", Font.BOLD, 25); jfreechart.getTitle().setFont(font); font = new Font("宋体", Font.PLAIN, 12); LegendTitle legendTitle = jfreechart.getLegend(); if (null != legendTitle) { legendTitle.setItemFont(font); // 图例文字字体 } CategoryPlot categoryplot = jfreechart.getCategoryPlot(); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); font = new Font("宋体", Font.PLAIN, 16); categoryaxis.setLabelFont(font); // x轴名称的字体 categoryplot.getRangeAxis().setLabelFont(font); // y轴名称的字体 font = new Font("宋体", Font.PLAIN, 10); categoryaxis.setTickLabelFont(font); // x轴上的刻度名称字体 categoryplot.getRangeAxis().setTickLabelFont(font); // y轴上的刻度名称字体 font = new Font("宋体", Font.PLAIN, 18); categoryplot.setNoDataMessage("No Data"); categoryplot.setNoDataMessageFont(font); }