Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 703
Jav_Rock Avatar asked May 10 '11 10:05

Jav_Rock


2 Answers

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.

like image 150
Aaron Avatar answered Nov 15 '22 12:11

Aaron


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

like image 33
trashgod Avatar answered Nov 15 '22 11:11

trashgod