gpt4 book ai didi

JavaFX BarChart - Y 轴的最小值

转载 作者:行者123 更新时间:2023-11-30 07:07:56 26 4
gpt4 key购买 nike

我的数据从 750 000 - 1 000 000+ 变化,所以我实际上不需要看到低于 750 000 的值。

如果我只是使 y[i] - 750 000 那么还有另一个问题(在 AxisY 上显示最小值 0 到 250 000+-)

我怎样才能用BarChart做到这一点?

BarChart<String,Number> bc= new BarChart<String, Number>(xAxis,yAxis);//statistic-years
bc.setTitle("Statistic-Years");
xAxis.setLabel("Country");
yAxis.setLabel("Value");
int[] cityPopulation = {
857200, 866500,871100,880400,889600,891900, 889800, 882100, 873200, 864400, 854300, 844300, 831500, 818910,
816382, 814255,813159,811939,812990,812862, 812605, 814224, 814070, 815786, 816061, 815269, 814758, 813387};
int[] countryPopulation = {
1075400,1059100,1043300,1028000,1022300,1012900,999900,993100,987300,980200,974400,966700,959500,953461,937490,
921981, 906978, 889632, 873477, 859355, 847370, 836384,827131,818401,810977,802993,795815,788776,
};
XYChart.Series series1 = new XYChart.Series();
series1.setName("Country population");
XYChart.Series series2 = new XYChart.Series();
series2.setName("City population");
bc.setStyle("-fx-font-size: 14;-fx-font-weight: bolder;");
bc.setStyle("CHART_COLOR_1: rgb(2,0,94); " + "CHART_COLOR_2: rgb(189,0,18); ");
for (int i =0;i<cityPopulation.length;i++) {
series1.getData().add(new XYChart.Data(""+(i+1989),countryPopulation[i]));
series2.getData().add(new XYChart.Data(""+(i+1989),cityPopulation[i]));
}
bc.getData().add(series1);
bc.getData().add(series2);

最佳答案

该轴具有这些边界,因为 autoRangingProperty 的默认值为 trueforceZeroInRangeProperty 的默认值也是true

这意味着,轴将自动设置自己的边界,同时始终显示零值,因此下限至少为零。

您可以将forceZeroInRangeProperty设置为false,这将导致自动测距,但由于不强制显示零值,因此将根据上的最小值和最大值计算边界显示的数据。

yAxis.setForceZeroInRange(false);

或者,您可以手动设置轴边界:

例如使用适当的 constructor设置下限和上限:

NumberAxis yAxis = new NumberAxis(700000, 1200000, 1000);

或者将 autoRangingProperty 设置为 false 并将 lowerBoundProperty 设置为 falseupperBoundProperty到所需的值:

NumberAxis yAxis = new NumberAxis();
yAxis.setAutoRanging(false);
yAxis.setLowerBound(700000);
yAxis.setUpperBound(1200000);

forceZeroInRangeProperty 设置为 false 的示例图表:

enter image description here

关于JavaFX BarChart - Y 轴的最小值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39765138/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com