Rendering Custom color for the Bars (Newbie)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
vijay
Posts: 13
Joined: Thu Nov 17, 2005 3:20 pm
Location: India

Rendering Custom color for the Bars (Newbie)

Post by vijay » Thu Nov 17, 2005 3:44 pm

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]

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Nov 17, 2005 5:29 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

vijay
Posts: 13
Joined: Thu Nov 17, 2005 3:20 pm
Location: India

Post by vijay » Mon Nov 21, 2005 9:28 am

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

Locked