jfreechart 中文乱码
时间: 2023-07-09 07:49:48 浏览: 122
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());
```
以上两种方法都可以尝试一下,看看是否能解决中文乱码的问题。
阅读全文