首页 > 解决方案 > 如何获取栏顶部的数字

问题描述

我用 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();

标签: javacssjavafxbar-chart

解决方案


推荐阅读