如何在禁用自动计算的情况下在 ValueAxis 上设置边距?

How to set a margin on a ValueAxis with auto-calculate disabled?

我使用 JFreeChart 通过 Apache PdfBox 显示 PDF 格式的图表。

我的问题是:我有一个散点图(附图),它有固定的下限和上限,所以自动计算不是一个选项。图表显示带有结果的蓝点。但是,如果dot的值为0或2(边缘值),则dot被切掉,所以我需要在这种情况下设置边距。我试过 xAxis.setUpperMargin,但没有成功。

这是部分代码:

NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
double tickSize = maxValue > 10 ? 1 : 0.5;
xAxis.setTickUnit(new NumberTickUnit(tickSize));
xAxis.setRange(1, maxValue);

如您所见,“margin is added only when the axis range is auto-calculated—if you set the axis range manually, the margin is ignored." Alternatively, you can add a suitable margin when manually setting the range. Starting from this example,以下对 adjustAxis() 的更改会在每个轴的两端增加 10% 的边距,从而产生所示结果。

axis.setRange(-1.1, 1.1);