R – Create barchart using jfreechart with bars of same category together

categoriesgaps-in-visualsgroupingjfreechartseries

I want to make bar chart using jfreechart such that the bars which belong to the same category should be displayed adjacent without any gaps. The categories should be displayed with gaps.
Also each category may have different number of bars.
How it can be achived using Jfreechart library?
Following image is the sample of what I require.
Here all the bars of same category should be of same color and with no gap(or a very little gap).

alt text

Thanks in advance,
Abhinav

Best Answer

I am aware of the age of this post. Anyway I am posting my solution, maybe someone else who will find himself here looking for the answer will find it useful.

I was looking for the answer but didn't find it and had to figure it out myself.

That is the code I use:

BarRenderer br = new BarRenderer();
br.setItemMargin(0.0);
chart.getCategoryPlot().setRenderer(br);
Related Topic