Hi,
I have a single row and multiple columns for BarChart and i would like to control the color of each bar. Can anyone let me know i can achieve this.
Here is the snippet of my dataset.
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(11.0, "S1", "C1");
dataset.addValue(44.3, "S1", "C2");
dataset.addValue(93.0, "S1", "C3");
dataset.addValue(35.6, "S1", "C4");
dataset.addValue(75.1, "S1", "C5");
return dataset;
So i would like to render of each of these bars.(c1..c5) with a custom color. c1 in blue, c2 in red, c3 in green, and so on.
Does BarRenderer provide a way to define the color for each of these bars ? If not how can the same be achieved or any pointers?
Thanks,
Vijay
[/code]
Rendering Custom color for the Bars (Newbie)
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Generally JFreeChart uses one color per series, so that the series can be identified from the legend. You can change that by overriding the getItemPaint() method in the renderer to return different colors for each item. An example is BarChartDemo3 (the source code is included with the JFreeChart Developer Guide).
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Hi Dave,
Thanks for letting me know how i can get this done. My use case is kind of different, hence i am having to do this little tweaking. I have a purchased copy of the developers guide through one of our colleagues. I have been going through the documents. I have few feedback which i will post sometime from now, once i have gone through most of it in the docs.
Vijay
Thanks for letting me know how i can get this done. My use case is kind of different, hence i am having to do this little tweaking. I have a purchased copy of the developers guide through one of our colleagues. I have been going through the documents. I have few feedback which i will post sometime from now, once i have gone through most of it in the docs.
Vijay