#自定义柱形图颜色 ##参数说明 * chartTitle 标题 * categoryLabel x轴标题 * valueLabel y轴标题 * rowKeys 每个柱形图的名称 * columnKeys x轴数据名称 * @param data 数据 * @param chartPath 生成图片地址
public static void buildBarChat2(String chartTitle, String categoryLabel, String valueLabel, String[] rowKeys, String[] columnKeys, double[][] data, String chartPath) { CategoryDataset datasetNew = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data); //创建主题样式 StandardChartTheme mChartTheme = new StandardChartTheme("CN"); //设置标题字体 mChartTheme.setExtraLargeFont(new Font("黑体", Font.BOLD, 24)); //设置轴向字体 mChartTheme.setLargeFont(new Font("黑体", Font.PLAIN, 15)); //设置图例字体 mChartTheme.setRegularFont(new Font("黑体", Font.PLAIN, 15)); //应用主题样式 ChartFactory.setChartTheme(mChartTheme); JFreeChart chart = ChartFactory.createBarChart(chartTitle, categoryLabel, valueLabel, datasetNew, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = chart.getCategoryPlot(); // 设置网格背景颜色 plot.setBackgroundPaint(Color.white); // 设置网格竖线颜色 // plot.setDomainGridlinePaint(Color.pink); // 设置网格横线颜色 // plot.setRangeGridlinePaint(Color.pink); //x轴 CategoryAxis mDomainAxis = plot.getDomainAxis(); //设置x轴标题的字体 mDomainAxis.setLabelFont(new Font("黑体", Font.PLAIN, 18)); //设置x轴坐标字体 mDomainAxis.setTickLabelFont(new Font("黑体", Font.PLAIN, 16)); //y轴 ValueAxis mValueAxis = plot.getRangeAxis(); //设置y轴标题字体 mValueAxis.setLabelFont(new Font("黑体", Font.PLAIN, 18)); //设置y轴坐标字体 mValueAxis.setTickLabelFont(new Font("黑体", Font.PLAIN, 16)); // 自定每个柱的颜色 String[] colorValues = { "#19A15F", "#4C8BF5","#087112", "#2E6FAF","#5A5AD6", "#292798","#08D1F0" }; BarRenderer renderer = (BarRenderer) plot.getRenderer(); for (int i=0;i
##效果图