开发者

Create barchart using jfreechart with bars of same category together

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 displa开发者_如何学编程yed 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).

Create barchart using jfreechart with bars of same category together

Thanks in advance, Abhinav


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜