javajfreechart

jfreechart - remove spaces in chart


I am using JFreeChart, and I want to remove the left and right spaces in my waterfall chart.

Here is what my chart looks like right now with the red squiggles to demonstrate the space I want to remove.

WaterfallChart

Any idea how to remove these spaces?


Solution

  • Because ChartFactory.createWaterfallChart() instantiates a CategoryAxis, simply set the relevant margins:

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0);
    domainAxis.setUpperMargin(0);
    

    Addendum: Note that negative values make the margin smaller, as illustrated here.

    domainAxis.setLowerMargin(-0.05);
    domainAxis.setUpperMargin(-0.05);