Which type of Jfreechart is more suitable for Histograms?
Asked Answered
P

2

5

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?

Primulaceous answered 10/5, 2011 at 10:46 Comment(0)
I
6

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.

Incarnadine answered 10/5, 2011 at 18:28 Comment(2)
+1 I think this is the better approach, but I've included this alternative.Soredium
Thanks, I did it this way and it worked. I also used GradientPaint, which makes a pretty cool effect. Thanks again.Primulaceous
S
3

For arbitrary colors within a series, you can override getItemPaint(), as shown here.

Soredium answered 10/5, 2011 at 18:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.