multi-color bar chart, and axis labels

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

multi-color bar chart, and axis labels

Post by Rich Unger » Thu Sep 05, 2002 1:18 am

I'm generating a bar chart where each bar is a different color. I'm doing it by making a 1-category, n-series CategoryDataset, and calling plot.setSeriesPaint(Paint[]) to apply my desired color set.

What I can't figure out is how to label each bar in the axis.

Thanks,
Rich

David Gilbert

Re: multi-color bar chart, and axis labels

Post by David Gilbert » Thu Sep 05, 2002 8:19 am

Hi Rich,

In 0.9.3, you can now use 1 series and n categories, and in the renderer call the setCategoriesPaint(...) method to specify the colors for the categories.

Regards,

DG.

Rich Unger

Re: multi-color bar chart, and axis labels

Post by Rich Unger » Thu Sep 05, 2002 7:45 pm

I tried it, and I'm just getting red throughout. My code is:

Color[] colors = { Color.yellow, Color.blue };

AbstractCategoryItemRenderer renderer =
(AbstractCategoryItemRenderer)plot.getRenderer();

renderer.setCategoriesPaint( colors );

If I change my data to be n-series, 1-category, and replace the last call with:

plot.setSeriesPaint( colors );

I get the right colors.

Rich

Rich Unger

Re: multi-color bar chart, and axis labels

Post by Rich Unger » Thu Sep 05, 2002 8:05 pm

Ah, I see why. I'm using a horizontal 3d bar chart, and I see the useCategoriesPaint property is only read in the VerticalBarRenderer.

Rich Unger

Re: multi-color bar chart, and axis labels

Post by Rich Unger » Thu Sep 05, 2002 8:43 pm

Update: So, I got it working with HorizontalBarRenderer just by adding the same if( ) statement that's in VerticalBarRenderer.

Paint itemPaint = null;
if( !this.useCategoriesPaint ) {
itemPaint = plot.getSeriesPaint(series);
}
else {
itemPaint = getCategoryPaint(categoryIndex);
}
g2.setPaint(itemPaint);

I didn't particularly want to touch the 3d renderers at the moment. If I'm not too pressed for time on my current project, I'll take a look at them. Are there any gotchas that would make them more difficult?

Rich

Rich Unger

Re: multi-color bar chart, and axis labels

Post by Rich Unger » Thu Sep 05, 2002 8:54 pm

Ah, what the hell. I took a quick glance at the 3d renderers, and it was easy :)

Locked