柱状图(CategoryPlot):
- Font font = new Font("宋体", Font.PLAIN, 16);
- // 设置标题的字体
- chart.getTitle().setFont(font);
- // 获取图表区域对象
- CategoryPlot plot = chart.getCategoryPlot();
- CategoryAxis domainAxis = plot.getDomainAxis();
- // 水平底部标题
- domainAxis.setLabelFont(font);
- // 水平底部列表
- domainAxis.setTickLabelFont(font);
- ValueAxis rangeAxis = plot.getRangeAxis();
- // 垂直标题
- rangeAxis.setLabelFont(font);
- // 设置图例字体
- chart.getLegend().setItemFont(font);
饼图(PiePlot):
- Font font = new Font("宋体", Font.PLAIN, 16);
- // 设置标题字体
- chart.getTitle().setFont(font);
- // 获取图表区域对象
- PiePlot piePlot = (PiePlot) chart.getPlot();
- piePlot.setLabelFont(font);
- chart.getLegend().setItemFont(font);
时序图(TimeSeries):
- Font font = new Font("宋体", Font.PLAIN, 16);
- // 获取图表区域对象
- XYPlotplot = (XYPlot) chart.getPlot();
- // Y轴字体
- plot.getRangeAxis().setLabelFont(font);
- // X轴框里的标题字体
- chart.getLegend().setItemFont(font);
- // X轴列表字体
- plot.getDomainAxis().setTickLabelFont(font);
- // X轴小标题字体
- plot.getDomainAxis().setLabelFont(font);
折线图:
- Font font = new Font("宋体", Font.PLAIN, 16);
- XYPlot plot = (XYPlot) chart.getPlot();
- // 设置标题字体
- chart.getTitle().setFont(font);
- CategoryAxis domainAxis = plot.getDomainAxis();
- // 设置X轴坐标上的文字
- domainAxis.setTickLabelFont(font);
- // 设置X轴的标题文字
- domainAxis.setLabelFont(font);
- NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
- // 设置Y轴坐标上的文字
- numberAxis.setTickLabelFont(font);
- // 设置Y轴的标题文字
- numberAxis.setLabelFont(font)
- // 解决底部汉字乱码的问题
- chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15));
- // 设置消除字体的锯齿渲染(解决中文问题)
- chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);