Jav_Rock
Jav_Rock

Reputation: 22245

Which type of Jfreechart is more suitable for Histograms?

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?

Upvotes: 5

Views: 1306

Answers (2)

trashgod
trashgod

Reputation: 205875

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

Upvotes: 3

Aaron
Aaron

Reputation: 5979

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.

Upvotes: 6

Related Questions