解决JFreeChart中文乱码问题

以下是解决X轴,Y轴中文字符乱码的代码:

JFreeChart chart = ChartFactory.createBarChart3D("管网损耗",// 图表标题
                    "时间(" + x_name + ")",// 目录轴的显示标签
                    "单位时间内损耗的能量", // 数值轴的显示标签
                    categoryDataset, // 数据集
                    PlotOrientation.VERTICAL,// 图表方向:水平、垂直
                    true, // 是否显示图例(对于简单的柱状图必须是false)
                    true,// 是否生成工具
                    false// 是否生成URL链接
                    );

            // 副标题
            TextTitle subtitle = new TextTitle(meterPosition + "表计管网损耗",
                    new Font("黑体", Font.BOLD, 12));
            chart.addSubtitle(subtitle);
            chart.setTitle(chart.getTitle()); // 标题

            CategoryPlot plot = chart.getCategoryPlot();// 获得图表区域对象
            // 设置图表的纵轴和横轴org.jfree.chart.axis.CategoryAxis
            CategoryAxis domainAxis = plot.getDomainAxis();
            NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();

            // 解决中文乱码问题
            TextTitle textTitle = chart.getTitle(); textTitle.setFont(new Font("黑体", Font.PLAIN, 20)); domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11)); domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 20)); numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 16)); chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));

 

你可能感兴趣的:(jfreechart)