Categories w/ different colors

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

Categories w/ different colors

Post by Kerry Shih » Wed Apr 24, 2002 6:25 pm

Using the horizontal bar chart, I can't find a way to get each category to have a different color. My only other requirement is to have one bar w/ one label. I have been doing one category w/ several series in order to set the labels. Any help would be appreciated.

Thanks,

Kerry

Kerry Shih

Re: Categories w/ different colors

Post by Kerry Shih » Wed Apr 24, 2002 6:36 pm

I should clarify. The end result should be a horizontal bar chart where each bar is a different color and each has a label that I can set.

Thanks

David Gilbert

Re: Categories w/ different colors

Post by David Gilbert » Fri Apr 26, 2002 10:54 am

The way the bar charts work is that all the bars in one series are the same color (and labelled in the legend if it is visible) and all the bars in one category are grouped together with a label on the axis.

To have a different color for each category would mean that there wouldn't be a single color to represent a series, so it wouldn't be possible to display a legend for the series. Of course, you don't really need a legend, since you only have one series.

One solution that various people have suggested in different forms in the past is:

Moved the getSeriesPaint(...) method from the Plot class to specific implementations in the subclasses of Plot, and add an extra parameter for the item or category. So in CategoryPlot it could become:

Paint getItemPaint(int series, Category category);

By default, this method could return a single color for each series, but there could be an option to change the color by category when a legend isn't required. Just thinking out loud, I haven't tried this out yet...

Regards,

DG.

Locked