0

I wrote a code with javafx and bar chart, I used a CCS style class, everything works fine, my question is if I can show the number on top of the bar in CCs file, or should I write code, and if so, how I can do that. can someone help me. here is my code from stage

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();
Malek
  • 1
  • 1
  • @DVarga yes I have seen this example before, I tried that, but I do not know if I used it correctly. Nothing happens.   where should I use this code exactly in the stage ?? – Malek Aug 16 '18 at 20:04
  • yes, it work now thank you @DVerga , but how can i get the hight of xAxis ?? is any methode to do that, i mean i want to put the value of yAxis on the top of bar ?? – Malek Aug 17 '18 at 09:53

0 Answers0