bars with title and colors?

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

bars with title and colors?

Post by eddy » Fri Jun 21, 2002 4:02 pm

Hi,

i need a bar chart with different colored bars and a title next to each bar, something like this:

title1 [bar1--color1------]
title2 [bar2--color2--------]
title3 [bar3--color3----------]
title4 [bar4--color4-----]
title5 [bar5--color5-------------]
title6 [bar5--color6--------]

with one category and many series I get the colors but only one category title. With many categories and one series I get the titles but just one color.

Is it possible ?

Thanks,

Eddy

David Gilbert

Re: bars with title and colors?

Post by David Gilbert » Fri Jun 21, 2002 5:28 pm

There's only one color per series...changing that would mess up the legend. However, if you really want to do it then you should make your own renderer...subclass HorizontalBarRenderer and override the draw method (that's where the series color is set).

Regards,

DG.

Nishan Krikorian

Re: bars with title and colors?

Post by Nishan Krikorian » Tue Jun 25, 2002 5:27 pm

Hi:

Several people have requested this, and I need it too. I have discovered a way that doesn't require any special coding at all. The key is to use stacked bar charts.

Think of chart data as a matrix where the rows are series and columns are categories. Build an nxn matrix of zeros, put your single series of data down the diagonal, and give this to a stacked vertical bar chart. The chart thinks you have n series each of which has nonzero data in a unique category and zeros elsewhere. Each category will have a different color (up to nine or whatever). The legend even works, although I usually turn it off.

I didn't think of this. My wife did. All credit to her.

Nish

Locked