Create barchart using jfreechart with bars of same category together

后端 未结 2 1048
生来不讨喜
生来不讨喜 2021-01-18 23:04

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

相关标签:
2条回答
  • 2021-01-19 00:07

    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);
    
    0 讨论(0)
  • 2021-01-19 00:08

    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 讨论(0)
提交回复
热议问题