首页 > 解决方案 > JavaFX BarChart - 主轴系列

问题描述

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

- 在此处输入图像描述

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);
    }
}

标签: javajavafx

解决方案


推荐阅读