Search code examples
javagraphbar-chartawtjfreechart

JFreeChart align Bar Chart left


I printed a bar chart using JFreeChart. But if I want to make the bars closer to each other using setCategoryMargin(-2) on my CategoryAxis, the Bar Chart appears to align in the center.

Is there a way to align the entire graph to the left, so it's directly next to the y-axis ? Or reduce the space between the bars without the chart getting centered ?


Solution

  • The setCategoryMargin(float) is used to adjust the space between categories and accepts a value between 0.0 and 1.0 (where 1.0 means 100% of the available space is used as the margin(!)). So using a negative value (-2) may not give the expected result.

    Read more: https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/CategoryAxis.html#setCategoryMargin-double-

    You can try setting different lower positive margin to to see what suits your needs.