JavaFX Tutorial 18 - BarChart Java GUI

Опубликовано: 25 Февраль 2025
на канале: Code Amir
836
6

JavaFX Tutorial 18 BarChart Java GUI
Code Source : https://bit.ly/3bZbgpG
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("TOP 10 LARGEST COUNTRIES BY POPULATION");

CategoryAxis xAxis = new CategoryAxis();
xAxis.setLabel("COUNTRIES");

NumberAxis yAxis = new NumberAxis();
yAxis.setLabel("POPULATION");

BarChart barChart = new BarChart(xAxis, yAxis);

XYChart.Series dataSeries1 = new XYChart.Series();
dataSeries1.setName("2020");

dataSeries1.getData().add(new XYChart.Data("China", 1438));
dataSeries1.getData().add(new XYChart.Data("India" , 1376));
dataSeries1.getData().add(new XYChart.Data("USA" , 330));
dataSeries1.getData().add(new XYChart.Data("Indonesia", 272));
dataSeries1.getData().add(new XYChart.Data("Pakistan" , 219));
dataSeries1.getData().add(new XYChart.Data("Brazil" , 212));
dataSeries1.getData().add(new XYChart.Data("Nigeria", 204));
dataSeries1.getData().add(new XYChart.Data("Bangladesh" , 164));
dataSeries1.getData().add(new XYChart.Data("Russia" , 145));
dataSeries1.getData().add(new XYChart.Data("Mexico" , 128));


barChart.getData().add(dataSeries1);

VBox vbox = new VBox(barChart);

Scene scene = new Scene(vbox, 800, 600);

primaryStage.setScene(scene);
primaryStage.setHeight(600);
primaryStage.setWidth(800);

primaryStage.show();
}

The JavaFX BarChart component is capable of drawing a bar chart inside your JavaFX applications. This is useful in dashboard-like applications. The JavaFX BarChart component is represented by the class javafx.scene.chart.BarChart
JavaFX BarChart