Create barchart using jfreechart with bars of same category together
Asked Answered
A

2

5

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

Anhedral answered 8/1, 2010 at 4:53 Comment(0)
K
5

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);
Karat answered 5/7, 2011 at 11:23 Comment(0)
C
4

You can do this with the setCategoryMargin() method on the domain axis.

For example with a Category Plot:

CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryMargin(0.15f);

You will need to play with different values for the margin to find the correct value for your graph.

Cyrano answered 1/2, 2010 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.