I would like to set a limit where bar graph change color.
For instance under 50, bar graph are blue and after 50 they are red.
Does anybody has already done somthing like this or has a cloud how
should I do ?
Thanks.
O.
change bar color depending of a limit
Re: change bar color depending of a limit
I presume you're talking about a bar chart with a single data series. You can do this with the setCategoriesPaint() method (see http://www.object-refinery.com/jfreecha ... .awt.Paint[]))
In 0.9.3, this will only take effect in one of the bar chart renderers (2d-horizontal I think). The code for the 2d and 3d horizontal and vertical bar renderers is checked into CVS, so presumably it will be in 0.9.4.
At any rate, you should be able to loop over your data set, and create a Color[] based on the values in that set. Then just call renderer.setCategoriesPaint(Color[]).
Cheers,
Rich
In 0.9.3, this will only take effect in one of the bar chart renderers (2d-horizontal I think). The code for the 2d and 3d horizontal and vertical bar renderers is checked into CVS, so presumably it will be in 0.9.4.
At any rate, you should be able to loop over your data set, and create a Color[] based on the values in that set. Then just call renderer.setCategoriesPaint(Color[]).
Cheers,
Rich
Re: change bar color depending of a limit
Alternatively, a custom renderer would be able to achieve this easily. Just subclass VerticalBarRenderer and override the drawItem(...) method (just cut and paste the method, then modify the color setting based on some value threshold that you could set as an attribute for your custom renderer).
Regards,
DG
Regards,
DG
Re: change bar color depending of a limit
I did it follow the suggestion. It works fine. However, it doesn't work if the Verical Bar Chart has 2 Series.
How can I solve it??
Thx,
Tony
How can I solve it??
Thx,
Tony
Re: change bar color depending of a limit
That's because the 'category paint' setting is for a special case where there is only one series (and you don't want one color for all the bars). I think you will find a better solution is to subclass VerticalBarRenderer, then you have full control over all the series...
Regards,
DG
Regards,
DG