Colors 根据键值更改堆叠条形图颜色

Colors 根据键值更改堆叠条形图颜色,colors,jfreechart,pie-chart,stackedbarseries,Colors,Jfreechart,Pie Chart,Stackedbarseries,我想使用键值修改stackedBarChart的颜色。我知道如何对piecharts执行此操作,但无法对stackedBarCharts执行相同的操作 对于piecharts,基本上我的方法与前面提到的答案类似 需要注意的代码行有: PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("J+1", Color.black); plot.setSectionPaint("J-1", new Color(120, 0, 120

我想使用键值修改stackedBarChart的颜色。我知道如何对piecharts执行此操作,但无法对stackedBarCharts执行相同的操作

对于piecharts,基本上我的方法与前面提到的答案类似

需要注意的代码行有:

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);
用于堆叠条形图?如果是,我如何使用它?


我可以从web资源中看到setSeriesPaint有些东西,但它似乎在根据索引改变颜色。我想根据标签更改颜色,例如“J+1”。

您可以覆盖渲染器的
getItemPaint()
方法,如图所示


谢谢。代码没有显示如何根据节标签定义颜色…您可以帮助详细说明吗?您还可以查看前面提到的自定义
绘图供应商。