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?
Bar colors
Re: Bar colors
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
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
Re: Bar colors
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.
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.