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
multi-color bar chart, and axis labels
Re: multi-color bar chart, and axis labels
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.
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.
Re: multi-color bar chart, and axis labels
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
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
Re: multi-color bar chart, and axis labels
Ah, I see why. I'm using a horizontal 3d bar chart, and I see the useCategoriesPaint property is only read in the VerticalBarRenderer.
Re: multi-color bar chart, and axis labels
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
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
Re: multi-color bar chart, and axis labels
Ah, what the hell. I took a quick glance at the 3d renderers, and it was easy 
