JFreeChart 解决编码问题
来源:互联网 发布:linux运维工资 编辑:程序博客网 时间:2024/06/05 10:18
在使用JFreeChart (http://www.jfree.org/jfreechart/ )做中文的图表时,中文乱码是一个最常要处理的问题,看网上许多文章都是在JFreeChart对象上下功夫,每次都得重新设置字体,比较麻烦。其实JFreeChart为我们提供了一个通用的解决方案——ChartTheme 。
ChartTheme有一个默认的实现类StandardChartTheme ,该类提供了图表主题的默认实现,通过ChartFactory 默认将这一实现应用到所有ChartFactory所生成的JFreeChart 对象中,你可以利用ChartFactory的setChartTheme(ChartTheme theme) 方法改变这一默认实现,让所有由ChartFactory生成的图表都应用你所指定的主题。
StandardChartTheme提供如下方法来定制字体:
- public void setExtraLargeFont(Font font)
- public void setLargeFont(Font font)
- public void setRegularFont(Font font)
- public void setSmallFont(Font font)
只要重写这几个方法,就可以制定出一个适合中文图表的主题了:
StandardChartTheme theme = new StandardChartTheme("unicode") {public void apply(JFreeChart chart) {chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);super.apply(chart);}};theme.setExtraLargeFont(new Font("宋体", Font.PLAIN, 20));theme.setLargeFont(new Font("宋体", Font.PLAIN, 14));theme.setRegularFont(new Font("宋体", Font.PLAIN, 12));theme.setSmallFont(new Font("宋体", Font.PLAIN, 10));ChartFactory.setChartTheme(theme);
重写apply(...)方法是为了借机消除文字锯齿.VALUE_TEXT_ANTIALIAS_OFF
ChartFactory.setChartTheme(theme); 用于将该主题作为工厂的默认主题。
- JFreeChart 解决编码问题
- jfreechart解决乱码问题。
- JfreeChart 解决中文乱码问题
- JFreeChart 解决中文乱码问题
- 解决JFreeChart中文乱码问题
- 解决JfreeChart中文乱码问题
- 解决JFreeChart无法正常显示中文问题
- 解决JFreeChart无法正常显示中文问题
- JFreeChart| JFreeChart问题集锦
- 解决MYSQL编码问题
- 解决MYSQL编码问题
- MyEclipse解决编码问题
- mysql解决编码问题
- PDO解决编码问题
- Struts2解决编码问题
- 解决字符串编码问题
- MD5解决编码问题
- Filter解决编码问题
- STL中的常用的vector,map,set,Sort用法
- 畅通工程hdu1232
- - - 谁把这老贴给翻出来的。。
- Ubuntu 10.04安装NVIDIA官方驱动的方法
- Delphi简单TCP聊天程序
- JFreeChart 解决编码问题
- NIO Buffer
- 据说是11年度最佳代码
- 22个很棒的jQuery文件上传插件
- 隔行模拟摄像头缺点
- 如果你在Windows下用putty来远程连接Linux发现乱码请用下面的方法解决:
- hdu 1690 Bus System--floyd
- shell:select 用法
- 头文件与之实现文件的的关系