2016-09-29 187 views
1

最小值我有變化的數據從750 000 - 1 000 000 + - 所以我實際上不需要看到下750 000JavaFX的條形圖 - 爲Y軸

值如果我只是使值Y [i] - 750 000所以還有另一個問題(在AxisY min 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); 

回答

1

軸具有這些邊界,因爲autoRangingProperty的默認值是trueforceZeroInRangeProperty的默認值也是true

這意味着,軸將自動設置自己的邊界,同時始終顯示零值,因此下限至少爲零。

您可以將forceZeroInRangeProperty設置爲false,這將導致自動測距,但由於不會強制顯示零值,因此將根據顯示的數據的最小值和最大值計算邊界。

yAxis.setForceZeroInRange(false); 

或者,也可以手動設定軸界限:使用例如此時,相應constructor設置下限和上限

或者:

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

或通過設置autoRangingPropertyfalselowerBoundPropertyupperBoundProperty到所需值:

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

例圖表通過設置forceZeroInRangeProperty爲false:

enter image description here

+0

哦非常感謝 試過只是這一個,但它未制訂出:/'yAxis.setLowerBound(700000);' – Ihor