Create barchart using jfreechart with bars of same category together

夙愿已清 提交于 2019-12-01 18:16:06

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!