如何正确使用 JFreeChart 自动调整范围?

How do I use JFreeChart auto ranges properly?

我在创建的图表上手动创建了 y 轴的范围,但看到有一些属性表明 JFreeChart 可以为您生成它们。

它已经为 y 轴生成了一个合理的最大值,但无论我尝试做什么,在生成图表时我都无法真正考虑到 setAutoRangeIncludesZero(boolean)

下面是生成和操作图表的相关代码:

barChart = ChartFactory.createBarChart("Classifiers' accuracy for " + position + "s", 
           "Missing Value Imputation Method Combination", 
           "Average accuracy (%)", dataset, 
           PlotOrientation.VERTICAL, true, false, false);

plot = (CategoryPlot)barChart.getCategoryPlot();
xAxis = (CategoryAxis)plot.getDomainAxis();
xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

yAxis = (NumberAxis)plot.getRangeAxis();
yAxis.setAutoRangeIncludesZero(false);

barChartImage = new File(position + "-Classification" + ".png");

我也试过首先使用 setAutoRange(true) 将 y 轴设置为 ValueAxis,然后将 y 轴转换为 NumberAxis 并使用 setAutoRangeIncludesZero(false) .

每次,y 轴仍然从 0 开始。

感谢@doublep 在私聊中的回答。

我使用的是条形图,结果 BarRenderer 默认情况下将范围的底数设置为 0。 要覆盖它,您只需要从绘图对象获取渲染器并将其转换为类型 BarRenderer,然后调用 setIncludeBaseInRange(false),这将防止默认值 0 包含在范围内。