JavaFX ScatterChart Example

In this JavaFX source code example, we will see how to create a Scatter Chart using JavaFX. 

A scatter chart is a set of points plotted on horizontal and vertical axes.

JavaFX ScatterChart Example

In the example, we use the ScatterChart to display gold prices.

package sample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Main extends Application {

    public void start(Stage stage) {


    private void initUI(Stage stage) {

        HBox root = new HBox();

        CategoryAxis xAxis = new CategoryAxis();
        NumberAxis yAxis = new NumberAxis("INR/10 gram", 40000, 60000, 10000);

        ScatterChart scatterChart = new ScatterChart<>(xAxis, yAxis);

        XYChart.Series data = new XYChart.Series<String, Number>();

        data.getData().add(new XYChart.Data<>("Jan 20", 43000));
        data.getData().add(new XYChart.Data<>("Mar 20", 45000));
        data.getData().add(new XYChart.Data<>("Jun 20", 42000));
        data.getData().add(new XYChart.Data<>("Jan 21", 48000));
        data.getData().add(new XYChart.Data<>("Aug 21", 50000));
        data.getData().add(new XYChart.Data<>("Dec 21", 52000));


        Scene scene = new Scene(root, 500, 400);

        stage.setTitle("Gold price in India");

    public static void main(String[] args) {

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course