JavaFX BarChart-离主轴系列

时间:2020-02-08 22:04:20

标签: java javafx

为什么小节偏离中心刻度线?为什么我不能控制栏的大小?

-enter image description here

public class DoubleSeriesBarChart extends Application {

    private BarChart<String, Number> chart;

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("BarChart Experiments");

        final CategoryAxis xAxis = new CategoryAxis();
        final NumberAxis yAxis = new NumberAxis();
        this.chart = new BarChart<>(xAxis,yAxis);
        this.chart.setAnimated(false);

        this.chart.setBarGap(0);
        this.chart.setCategoryGap(0);

        XYChart.Series series1 = new XYChart.Series();
        series1.setName("300");
        series1.getData().add(new XYChart.Data("A1", 25601.34));
        series1.getData().add(new XYChart.Data("A2", 20148.82));

        XYChart.Series series2 = new XYChart.Series();
        series2.setName("302.50");
        series2.getData().add(new XYChart.Data("B1", 57401.85));
        series2.getData().add(new XYChart.Data("B2", 41941.19));

        XYChart.Series series3 = new XYChart.Series();
        series3.setName("305");
        series3.getData().add(new XYChart.Data("C1", 45000.65));
        series3.getData().add(new XYChart.Data("C2", 44835.76));

        this.chart.getData().addAll(series1, series2, series3);

        VBox vbox = new VBox(this.chart);

        Scene scene = new Scene(vbox, 400, 600);
        primaryStage.setScene(scene);
        primaryStage.setWidth(400);
        primaryStage.setHeight(600);
        primaryStage.show();
    }

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

0 个答案:

没有答案
相关问题