Bar colors

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jason

Bar colors

Post by jason » Mon Jun 03, 2002 11:03 pm

How do you control the color of the bars in a vertical bar chart?

I am creating several small bar charts all with just one type of data, so all charts have red bars. Can I control the color of the bars on each chart?

Gaurav Kathotia

Re: Bar colors

Post by Gaurav Kathotia » Tue Jun 04, 2002 1:45 pm

Instead of populating data in a Many Categories-One Series fashion,
try using Many Series-One Categories fashion to get bars of different colours( Just inverse the order of your categorydataset array) from
[1][Categories] form to [Series][1] form.
Hope that helps
Gaurav Kathotia

David Gilbert

Re: Bar colors

Post by David Gilbert » Tue Jun 04, 2002 3:20 pm

You can change the color for each series using the setSeriesPaint(...) method in the Plot class. For example:

Plot plot = myChart.getPlot();
Paint[] colors = new Paint[] {Color.green, Color.yellow, Color.lightGray};
plot.setSeriesPaint(colors);

You would normally set the same number of colors as you have series in your dataset, but if you supply less colors then JFreeChart will just cycle through them again. Also, the array can hold any Paint object, not just the predefined Color constants.

Regards,

DG.

Locked