0

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 ?

matteo
  • 3
  • 4
  • You might explore relevant margins, as suggested [here](https://stackoverflow.com/a/9667294/230513); you can experiment with this complete [example](https://stackoverflow.com/a/17342522/230513). – trashgod Jun 26 '23 at 17:06
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 26 '23 at 17:43

1 Answers1

0

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.

Yahor Barkouski
  • 1,361
  • 1
  • 5
  • 21