Reputation: 1
My Bar chart is always drawn with a gradient fill. I have a code to fill each bar in a series with a different color. I just want the colors without any effect. I looked at a previous thread but that did not help since it seems to be designed for a default standard code.
Here is my code:
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
CategoryItemRenderer renderer = new MyRenderer();
plot.setRenderer(renderer);
class MyRenderer extends BarRenderer
{
private Paint[] barColors;
public MyRenderer()
{
this.barColors = new Paint[] { new Color( 21, 104, 156), new Color( 25, 149, 104), new Color( 237, 179,20),
new Color( 72, 181, 163) };
}
public Paint getItemPaint(final int row, final int column)
{
// returns color for each column
return (this.barColors[column % this.barColors.length]);
}
}
Any help will be appreciated.
Thanks.
Upvotes: 0
Views: 662
Reputation: 4477
In the BarRenderer
class you will find this method:
public static void setDefaultBarPainter(BarPainter painter);
It allows you to change the default bar painter (pass a StandardBarPainter
to this method before creating any charts and your charts will have bars without the gradient).
Upvotes: 2