`

jfreechart 1.0.13中文乱码问题的解决

阅读更多
将坐标图和饼状图中的中文乱码问题解决了,只要做如下配置:
/**
* 配置字体 解决导出图中的中文乱码问题
*
* @param chart
* JFreeChart 对象
*/
public static void configFont(JFreeChart chart) {
// 配置字体
Font font = new Font("宋体", Font.BOLD, 25);

chart.getTitle().setFont(font);
if (chart.getLegend() != null) {
chart.getLegend().setItemFont(font);
}
if (chart.getPlot() instanceof CategoryPlot) {
chart.getCategoryPlot().getDomainAxis().setLabelFont(font);
chart.getCategoryPlot().getDomainAxis().setTickLabelFont(font);
chart.getCategoryPlot().getRangeAxis().setLabelFont(font);
chart.getCategoryPlot().getRangeAxis().setTickLabelFont(font);
} else if (chart.getPlot() instanceof XYPlot) {
if (chart.getXYPlot().getDomainAxis() != null) {
chart.getXYPlot().getDomainAxis().setLabelFont(font);
chart.getXYPlot().getDomainAxis().setTickLabelFont(font);
}
if (chart.getXYPlot().getRangeAxis() != null) {
chart.getXYPlot().getRangeAxis().setLabelFont(font);
chart.getXYPlot().getRangeAxis().setTickLabelFont(font);
}
} else if (chart.getPlot() instanceof PiePlot) {
((PiePlot3D) chart.getPlot()).setLabelFont(font);
}
// 设置背景色
chart.setBackgroundPaint(Color.WHITE);
}
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics