javafx设置yAxis.setLowerBounds大于0

时间:2019-03-11 15:13:28

标签: java javafx

我有一个来自javafx的StackedBarGraph。
我正在尝试将下限设置为大于0.0的数字。
我认为这是StackedBarCharts的问题。
当我在Barchart上尝试时,它将正常工作。

// working          yAxis.setLowerBound(-10.0);
// working          yAxis.setLowerBound(0.0);
// not working      yAxis.setLowerBound(5.0);


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;

public class JavaGraphTest extends Application {

    @Override
    public void start(Stage stage) {
        try {

            stage.setTitle("Lotto Tracking Graph");

            final CategoryAxis xAxis = new CategoryAxis();
            final NumberAxis yAxis = new NumberAxis();
            final StackedBarChart<String,Number> bc =   new StackedBarChart<>(xAxis,yAxis);
            Scene scene = new Scene(bc,800,600);

            yAxis.setLabel("Count");

            yAxis.setAutoRanging(false);
            yAxis.setForceZeroInRange(false);

 // The is the only change made

    // working          yAxis.setLowerBound(-10.0);
    // working          yAxis.setLowerBound(0.0);
    // not working      yAxis.setLowerBound(5.0);



            yAxis.setUpperBound(60);

            XYChart.Series<String, Number> series1 = new XYChart.Series<>();
            XYChart.Series<String, Number> series2 = new XYChart.Series<>();

            Integer x, y=-6;
            for(x = 1; x<55 ; x++) {

                series1.getData().add(new XYChart.Data<String, Number>(x.toString(), x + y));
                series2.getData().add(new XYChart.Data<String, Number>(x.toString(),  y));

            };
            bc.getData().addAll(series1);
            bc.getData().addAll(series2);
            stage.setScene(scene);
            stage.setMaximized(true);
            stage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }

}

此类的源代码可用吗?

0 个答案:

没有答案