0

In jfreechart, I have a renderer such as

GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();

I my example I have 4 groups of 5 stacked bars (2 bars each stack), all in all 40 bars.

I have used a construction like

renderer.setSeriesPaint(0 + 2 * (length * s + g), <color for this bar>);
renderer.setSeriesPaint(1 + 2 * (length * s + g), <color for this bar>);

in order to color each bar individually, where g denotes the group, 'length' is the number of groups, s the stacked bar number within the group.

Unfortunately this does not work. What am I doing wrong?

alrts
  • 338
  • 5
  • 12

1 Answers1

1

You should be able to create any color scheme you want by overriding getItemPaint(), as shown in this example. Note the use of StandardXYBarPainter. It may help to print out a few values, as shown here. If not, please edit your question to include an sscce that shows your approach.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I can't see how to select colors for each bar from your answer. but I have found out the following: I'm filling the 40 bars with – alrts Oct 07 '12 at 09:16
  • ... categoryset.addValue(value, rowkey, columnkey) and then try to color each bar with renderer.getSeriesPaint(barNumber, color). However, only the first 10 barNumbers (0 to 9) take effect. This corresponds to the first group of bars. The remaining 3 groups of bars are colored the same as the first group. I need a function like setBarPaint() but this apparently does not exist. Could you be a bit more specific, please? – alrts Oct 07 '12 at 09:22
  • Please edit your question to include an [sscce](http://sscce.org/) that shows how you override `getItemPaint()`, as shown in the examples cited. – trashgod Oct 07 '12 at 15:56