views:

409

answers:

1

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

A: 

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.

Aaron