jfreechart中文乱码问题

 

jfreechart在默认状态靠的是StandardChartTheme来控制报表的一些主题的,因此可以重写此主题便可以了,

一般创建chart是靠的ChartFactory,因此jfreechart也是在CreateFactory为每一个createXXXChart应用到了默认的主题,此类的setChartTheme(CharTheme theme)可以更改主题设置因此只需要重写

 

然后再调用ChartFactory.createXXXChart();便可以了

可以进一步封装为一个类,方面不同地方的调用

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jfreechart 中文乱码问题通常是由于字体设置不正确所导致的。可以尝试以下方法来解决这个问题: 1. 设置字体:在创建图表之前,使用以下代码设置字体: ``` Font font = new Font("SimSun", Font.PLAIN, 12); ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme() .deriveLargeFont(font) .deriveRegularFont(font) .deriveExtraLargeFont(font) .deriveSmallFont(font)); ``` 2. 设置编码:在创建图表之前,使用以下代码设置编码: ``` ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); ChartFactory.getChartTheme().setExtraLargeFont(new Font("宋体", Font.BOLD, 20)); ChartFactory.getChartTheme().setLargeFont(new Font("宋体", Font.BOLD, 14)); ChartFactory.getChartTheme().setRegularFont(new Font("宋体", Font.PLAIN, 12)); ChartFactory.getChartTheme().setSmallFont(new Font("宋体", Font.PLAIN, 10)); ChartFactory.getChartTheme().setAxisLabelPaint(new Color(51, 51, 51)); ChartFactory.getChartTheme().setChartBackgroundPaint(Color.white); ChartFactory.getChartTheme().setLegendBackgroundPaint(Color.white); ChartFactory.getChartTheme().setLegendItemPaint(new Color(51, 51, 51)); ChartFactory.getChartTheme().setPlotBackgroundPaint(Color.white); ChartFactory.getChartTheme().setPlotOutlinePaint(Color.white); ChartFactory.getChartTheme().setTickLabelPaint(new Color(67, 67, 72)); ChartFactory.getChartTheme().setAxisOffset(new RectangleInsets(0, 0, 0, 0)); ChartFactory.getChartTheme().setBarPainter(new StandardBarPainter()); ChartFactory.getChartTheme().setXYBarPainter(new StandardXYBarPainter()); ChartFactory.getChartTheme().setAxisLabelInsets(new RectangleInsets(0, 0, 0, 0)); ChartFactory.getChartTheme().setAxisTickStroke(new BasicStroke(1.0f)); ChartFactory.getChartTheme().setBarPainter(new StandardBarPainter()); ChartFactory.getChartTheme().setXYBarPainter(new StandardXYBarPainter()); ``` 以上两种方法都可以尝试一下,看看是否能解决中文乱码问题

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值