I am working with JFreeChart in order to show a Histogram Chart. My idea is to create a chart with 10 double bars, one bar of the pair in a different color. The 10 values will correspond to 10 weeks, so every week I will have 2 bars representing two different datasets.
For this purpose I tried with class BarChart, and it works, but I am not able to asign different colors to each dataset.
If anybody could help with assigning different colors to each bar it would be great. Maybe another class is more suitable than BarChart?
The appearance of the bars is controlled by the renderer assigned to the category plot of the bar chart.
With the BarRenderer you can change the colour for each individual bar with the setSeriesPaint() method.
You can access the renderer from the chart by calling getCategoryPlot().getRenderer()
on your chart.
For arbitrary colors within a series, you can override getItemPaint()
, as shown here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With