JavaFX Stacked Bar Chart上的累积数字错误

时间:2015-06-18 15:13:49

标签: java javafx javafx-8

我正在尝试使用JavaFX 8构建堆积条形图,并且某些条形图的累积值未以图形方式正确再现。

为了说明问题,请考虑以下程序,提取from here,稍作修改即可解决问题:

import java.util.Arrays;
import javafx.application.Application;
import javafx.collections.FXCollections;
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 StackedBarChartSample extends Application {

    final static String austria = "Austria";
    final static String brazil = "Brazil";
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final StackedBarChart<String, Number> sbc =
            new StackedBarChart<>(xAxis, yAxis);
    final XYChart.Series<String, Number> series1 =
            new XYChart.Series<>();
    final XYChart.Series<String, Number> series2 =
            new XYChart.Series<>();
    final XYChart.Series<String, Number> series3 =
            new XYChart.Series<>();

    @Override
    public void start(Stage stage) {
        stage.setTitle("Bar Chart Sample");
        sbc.setTitle("Wrong accumulative values example");
        xAxis.setLabel("Country");
        xAxis.setCategories(FXCollections.<String>observableArrayList(
                Arrays.asList(austria, brazil)));
        yAxis.setLabel("Value");
        series1.setName("2003");
        series1.getData().add(new XYChart.Data<>(austria, 9.5));
        series1.getData().add(new XYChart.Data<>(brazil, 10));
        series2.setName("2004");
        series2.getData().add(new XYChart.Data<>(austria, 9.3));
        series2.getData().add(new XYChart.Data<>(brazil, 10));
        series3.setName("2005");
        series3.getData().add(new XYChart.Data<>(austria, 11.2));
        series3.getData().add(new XYChart.Data<>(brazil, 10));
        Scene scene = new Scene(sbc, 800, 600);
        sbc.getData().addAll(series1, series2, series3);
        stage.setScene(scene);
        stage.show();
    }

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

可以看出,奥地利和巴西的酒吧总和增加了30个。然而,在生产的图表中,奥地利的酒吧似乎加起来不到30个。

我有什么遗失的吗?

我在Ubuntu 14.04上使用jdk1.8.0_31。

提前致谢。

0 个答案:

没有答案