如何在栏的顶部获取数字

时间:2018-08-16 14:30:45

标签: java css javafx bar-chart

我用javafx和条形图编写了代码,我使用了CCS样式类,一切正常,我的问题是,是否可以在CCs文件中的条形顶部显示数字,还是应该编写代码?所以,我该怎么做。有人能帮我吗。这是我来自阶段的代码

public void start(Stage _stage) {
    try {
        _stage.setTitle(" Chart bar");

        final CategoryAxis xAxis = new CategoryAxis();
        xAxis.setLabel("field");

        final NumberAxis yAxis = new NumberAxis();
        yAxis.setLabel("Output Value");

        final BarChart<String, Number> bc = new BarChart<String, Number>(xAxis, yAxis);
        bc.setAnimated(false);
        bc.setAlternativeColumnFillVisible(false);
        bc.setAlternativeRowFillVisible(false);
        bc.setCache(false);
        bc.setTitle(" values");
        bc.setBarGap(1);
        bc.setCategoryGap(1);

        XYChart.Series serie = new XYChart.Series();
        serie.setName("field value");           

        for (int i = 2; i < data.length-2; ++i) {
            data[i] = 0;
                serie.getData().add(i-2, new XYChart.Data(fieldName[i-2], data[i]));

             }



        bc.getData().addAll(serie);



        _stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent we) {
                Platform.setImplicitExit(false);
                Platform.exit();
                quitRequest = true;
            }
        });




        Scene scene = new Scene(bc, 800, 400);
        _stage.setScene(scene);

        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        _stage.show();

0 个答案:

没有答案