×

JavaFX Bubble Chart

In the JavaFX application, in order to create Bubble Chart, the BubbleChart class is used. The Bubble Chart allows us to plot three dimensional data. All methods needed for this purpose are present in the javafx.scene.chart.BubbleChart class.

The constructor of the Bubble Chart:

1. BubbleChart(Axis x, Axis y):

It is used to create the bubble Chart with specified x and y-axis.

2. BubbleChart(Axis x, Axis y, ObseravableList newlist):

It is used to create a bubble Chart with specified x, y-axis, and specified new data.

Charts in JavaFX applications- Bubble Chart showing Age-Height relation:

Example:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.BubbleChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;


public class ChartUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    NumberAxis newxAxis = new NumberAxis(0, 35, 5);        
         newxAxis.setLabel("Age"); 
           
         NumberAxis newyAxis = new NumberAxis(10, 180, 10); 
         newyAxis.setLabel("Height"); 
         
         BubbleChart bubbleChart = new BubbleChart(newxAxis, newyAxis);    
            
         XYChart.Series series = new XYChart.Series();  
         series.setName("Age-Height chart"); 
            
         series.getData().add(new XYChart.Data(5,20,2));  
         series.getData().add(new XYChart.Data(10,70,4)); 
         series.getData().add(new XYChart.Data(15,90,5)); 
         series.getData().add(new XYChart.Data(20,150,6));    
         series.getData().add(new XYChart.Data(25,170,7));        
         
         bubbleChart.getData().add(series); 
            
         Group root = new Group(bubbleChart); 
            
         Scene scene = new Scene(root, 600, 400);  
        primaryStage.setScene(scene);  
        primaryStage.setTitle("JavaFX Chart - Bubble Chart Example");  
        primaryStage.show();  
          
    }  
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Bubble Chart in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.chart.BubbleChart, javafx.scene.chart.CategoryAxis, javafx.scene.chart.NumberAxis, javafx.scene.chart.XYChart, javafx.stage.Stage.

Then we have created one class named ChartUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a Bubble Chart, a BubbleChart object is created which is then passed to the Scene class object.

Bubble Chart is created with the help of its constructor with the x axis and y axis passed in the constructor. XYSeries data is created and passed to the constructor.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX Chart – Area Chart Example". Also, it displays an area chart showing the rainfall along different months.

Charts in JavaFX applications- Bubble Chart

Charts in JavaFX applications- Area Chart showing sales of 2 shops:

Example:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.BubbleChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.paint.Color;
import javafx.stage.Stage;


public class ChartUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
      NumberAxis newxAxis = new NumberAxis(1, 53, 4);
          NumberAxis newyAxis = new NumberAxis(0, 80, 10);
          BubbleChart<Number,Number> chart = 
             new BubbleChart<Number,Number>(newxAxis,newyAxis);
         newxAxis.setLabel("Week");
         newxAxis.setTickLabelFill(Color.RED);
         newxAxis.setMinorTickCount(4);
        
         newyAxis.setLabel("Sale");
         newyAxis.setTickLabelFill(Color.BLUE);
         newyAxis.setTickLabelGap(10);
         newyAxis.setTickLabelFormatter(
             new NumberAxis.DefaultFormatter(newyAxis,"$ ",null)
         );
                               
         chart.setTitle("Sales Chart");
         
         XYChart.Series series1 = new XYChart.Series();
         series1.setName("Shop 1");
         series1.getData().add(new XYChart.Data(3, 35, 2));
         series1.getData().add(new XYChart.Data(12, 60, 1.8));
         series1.getData().add(new XYChart.Data(15, 15, 7));
         series1.getData().add(new XYChart.Data(22, 30, 2.5));
         series1.getData().add(new XYChart.Data(28, 20, 1));
         series1.getData().add(new XYChart.Data(35, 41, 5.5));
        
                 
         XYChart.Series series2 = new XYChart.Series();
         series2.setName("Shop 2");
         series2.getData().add(new XYChart.Data(8, 15, 2));
         series2.getData().add(new XYChart.Data(13, 23, 1));
         series2.getData().add(new XYChart.Data(15, 45, 3));
         series2.getData().add(new XYChart.Data(24, 30, 4.5));
         series2.getData().add(new XYChart.Data(38, 78, 1));
         series2.getData().add(new XYChart.Data(40, 41, 7.5));
         chart.getData().addAll(series1, series2);     


                        
         Scene scene  = new Scene(chart);
        primaryStage.setScene(scene);  
        primaryStage.setTitle("JavaFX Chart - Bubble Chart Example");  
        primaryStage.show();  
          
    }  
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Area Chart in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.chart.AreaChart, javafx.scene.chart.CategoryAxis, javafx.scene.chart.NumberAxis, javafx.scene.chart.XYChart, javafx.stage.Stage.

Then we have created one class named ChartUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold the sales Area Chart, an AreaChart object is created which is then passed to the Scene class object.

Area Chart is created with the help of its constructor with the x axis and y axis passed in the constructor. XYSeries data is created and passed to the constructor.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is invoked. In output Frame like container is displayed with the title, " JavaFX Chart – Area Chart Example". Also, it displays an area chart showing the sales of 2 shops. It shows the sales comparision between 2 shops.

Charts in JavaFX applications- Bubble Chart

Related Topics

JavaFX Circle

In the JavaFX application, in order to draw a circle, the Circle class is used. The Circle allows us to join any points in the space. All methods needed for...

4 minutes read.

JavaFX Fade Transition

In the JavaFX application, in order to generate the fade transition, we have to apply fade transition on any particular shape. It has the ability to show the fading colors...

4 minutes read.

JavaFX Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

5 minutes read.

JavaFX HBox

In the JavaFX application, in order to set HBox as a layout, the HBox class is used. The HBox layout allows us to arrange the components in one row. All...

3 minutes read.

JavaFX Bubble Chart

In the JavaFX application, in order to create Bubble Chart, the BubbleChart class is used. The Bubble Chart allows us to plot three dimensional data. All methods needed for this...

4 minutes read.

JavaFX Rotate Transition

In the JavaFX application, in order to generate the rotate transition, we have to apply rotation transition on any particular shape. It has the ability to rotate the shape along...

4 minutes read.

JavaFX Area Chart

In the JavaFX application, in order to create Area Chart, the AreaChart class is used. The Area Chart allows us to plot data along the XY plane. All methods needed...

3 minutes read.

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine. Prerequisite: Operating systemAny Operating system (Windows, Linux, Mac)Memory requirementNo minimum requirementDisk SpaceNo minimum requirementJDK versionJDK...

3 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Selectors

In the JavaFX application, in order to apply various css effect, we use the various css classes available in the JavaFX. This is generally used to enhance the appearance property...

4 minutes read.

JavaFX PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.

JavaFX Color Input

In the JavaFX application, in order to apply various color input effect, we use the ColorInput class. It has the ability to fill the specified shape with a given color...

4 minutes read.

JavaFX Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX Slider

In the JavaFX application, in order to slide over a range of data having values, Slider is used. It provides a pane with a Slider to move over a range...

4 minutes read.

JavaFX BorderPane

In the JavaFX application, in order to set Border Pane as a layout, the BorderPane class is used. The BorderPane layout allows us to arrange the components in the left,...

4 minutes read.

JavaFX ScrollBar

In the JavaFX application, in order to scroll over a range of values, ScrollBar is used. It is used to view long page contents. In order to use ScrollBar in...

4 minutes read.

JavaFX Line Chart

In the JavaFX application, in order to create a Line Chart, LineChart class is used. The LineChart allows us to plot markers point according to the entities on number axes....

4 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX Reflection

In the JavaFX application, in order to apply various reflection effect, we use this class. It has the ability to create the reflection of the given object. This effect adds...

4 minutes read.