Linux 下JFreeChart图形乱码问题解决

来源:互联网 发布:南风知我意微盘 编辑:程序博客网 时间:2024/06/03 19:12
JFreeChart默认字体有"Arial","Dialog", "Dialog", "SansSerif", "Tahoma"

而需要用到是宋体等中文字体时,JVM找不到相关字体文件,所以会显示乱码,解决方法如下。

第一步:

将Linux系统的字体目录作为JDK下面的一个字体目录连接。
ln -s $FONTS_PATH/FONT_DIR$JAVA_HOME/jre/lib/fonts/fallback

第二步:

在代码中(柱状图)

  1. Font font = new Font("宋体", Font.BOLD, 22);  
  2. jfreechart.getTitle().setFont(font); // 标题  
  3.   
  4. font = new Font("宋体", Font.PLAIN, 14);  
  5. jfreechart.getLegend().setItemFont(font); // 列类型的文字字体  
  6.           
  7. font = new Font("宋体", Font.PLAIN, 16);  
  8. categoryaxis.setLabelFont(font); // x轴名称的字体  
  9. categoryplot.getRangeAxis().setLabelFont(font); // y轴名称的字体  
  10.   
  11. CategoryPlot categoryplot = jfreechart.getCategoryPlot();  
  12. CategoryAxis categoryaxis = categoryplot.getDomainAxis();  
  13.   
  14. font = new Font("宋体", Font.PLAIN, 12);  
  15. categoryaxis.setTickLabelFont(font); // x轴上的刻度名称字体  
  16. categoryplot.getRangeAxis().setTickLabelFont(font); // y轴上的刻度名称字体  
  17.           
  18. font = new Font("宋体", Font.PLAIN, 18);  
  19. categoryplot.setNoDataMessage(emptyMsg);  
  20. categoryplot.setNoDataMessageFont(font); // 没有数据时的提示 


饼图

  1. PiePlot plot = (PiePlot)freeChart.getPlot();   
  2. plot.setLabelFont(new Font("宋体",Font.BOLD,15)); 



参考博客:http://ferreousbox.iteye.com/blog/395176


http://developer.51cto.com/art/201112/308902.htm


0 0
原创粉丝点击