JavaFX. As in Chart to establish the width of the values


  • QA Engineer

    Question: As in Chart to establish the width of the X axis. In the example, they display orange color. введите сюда описание изображения

    Code:

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.chart.BarChart;
    import javafx.scene.chart.CategoryAxis;
    import javafx.scene.chart.NumberAxis;
    import javafx.scene.chart.XYChart;
    import javafx.stage.Stage;
    

    public class TestChart extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
    final CategoryAxis xAxis = new CategoryAxis();
    //System.out.println(xAxis.getCategorySpacing());
    final NumberAxis yAxis = new NumberAxis();
    final BarChart<String, Number> chart = new BarChart<>(xAxis, yAxis);

        XYChart.Series series1 = new XYChart.Series();
        series1.getData().add(new XYChart.Data("V", 1));
        series1.getData().add(new XYChart.Data("O", 2));
    
        chart.getData().addAll(series1);
    
        Scene scene = new Scene(chart, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
    public static void main(String[] args) {
        launch(args);
    }
    

    }

    public class TestChart extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
    final CategoryAxis xAxis = new CategoryAxis();
    //System.out.println(xAxis.getCategorySpacing());
    final NumberAxis yAxis = new NumberAxis();
    final BarChart<String, Number> chart = new BarChart<>(xAxis, yAxis);

        XYChart.Series series1 = new XYChart.Series();
        series1.getData().add(new XYChart.Data("V", 1));
        series1.getData().add(new XYChart.Data("O", 2));
    
        chart.getData().addAll(series1);
    
        Scene scene = new Scene(chart, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
    public static void main(String[] args) {
        launch(args);
    }
    

    }



  • If I understand correctly, there must be a method. .setBarGap(3); who changes the distance between the stacks.

    The thickness of the poles itself is stretched dynamically.

    Here. https://docs.oracle.com/javafx/2/charts/bar-chart.htm ♪




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2