我想使用键值修改stackedBarChart 的颜色。我知道如何对饼图执行此操作,但无法对stackedBarCharts 执行相同操作。
对于饼图,基本上我的方法类似于此处所述的答案
需要注意的代码行是:
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionPaint("J+1", Color.black);
plot.setSectionPaint("J-1", new Color(120, 0, 120));
但是对于 StackedBarChart,我不确定该怎么做,基本上我必须修改下面现有的 jfreechart 代码:
public static JFreeChart createStackedBarChart(final String title,
final CategoryDataset dataset) {
JFreeChart sectorChart = ChartFactory.createStackedBarChart(title, "",
"", dataset, PlotOrientation.VERTICAL, true, false, false);
CategoryPlot plot = (CategoryPlot) sectorChart.getPlot();
formatCategoryPlot(plot);
sectorChart.getLegend().setBorder(0, 0, 0, 0);
sectorChart.setBorderVisible(false);
sectorChart.setBorderPaint(Color.white);
plot.setOutlineVisible(false);
StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
return Chart;
}
所以我的问题真的是,是否有相当于
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionPaint("J+1", Color.black);
堆叠条形图?如果是,我该如何使用它?
我可以从网络资源中看到关于 setSeriesPaint 的一些东西,但这似乎是根据索引改变颜色。我想根据标签更改颜色,例如“J+1”。