×

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 for this purpose are present in the javafx.scene.chart.AreaChart class. JavaFX Area Chart is generally used to represent quantitative data. This chart is used to plot the area from given points. The Line Chart only joins the data point but the Area Chart highlights the area covered under the given points.

The constructor of the Area Chart:

1. AreaChart(Axis x, Axis y):

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

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

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

Property of the Area Chart:

1. createSymbols:

This property is the Boolean property when it is set to true it shows that the symbols can be created for given data items for those symbols nodes are not given. setCreateSymbols(Boolean value) method is used to set this property.

Charts in JavaFX applications- Area Chart showing rainfall along different months:

Example:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.CategoryAxis;
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 
    {  
       CategoryAxis newxAxis = new CategoryAxis();  
           
          //defining the y Axis 
          NumberAxis newyAxis = new NumberAxis(100, 3000, 1500); 
          newyAxis.setLabel(" Rainfall ");  
          
          //Creating the Area chart 
          AreaChart<String, Number> areaChart = new AreaChart( newxAxis, newyAxis );
          areaChart.setTitle(" Average rainfall during  months ");        
             
          //Prepare XYChart.Series objects by setting data  
          XYChart.Series series1 = new XYChart.Series();  
          series1.setName(" Months "); 
          series1.getData().add(new XYChart.Data(" Jan ", 500)); 
          series1.getData().add(new XYChart.Data(" Feb ", 500)); 
          series1.getData().add(new XYChart.Data(" March ", 300)); 
          series1.getData().add(new XYChart.Data(" April " , 500)); 
          series1.getData().add(new XYChart.Data(" May ", 400));
          series1.getData().add(new XYChart.Data(" June ", 1000));  
          series1.getData().add(new XYChart.Data(" July ", 2200)); 
          series1.getData().add(new XYChart.Data(" August ", 3000)); 
          series1.getData().add(new XYChart.Data(" Sept ", 2000)); 
         
                    
          areaChart.getData().addAll(series1); 
             
          //Creating a Group object  
          Group root = new Group( areaChart ); 
             
          //Creating a scene object 
          Scene scene = new Scene( root, 600, 400 );  
        primaryStage.setScene(scene);  
        primaryStage.setTitle(" JavaFX Chart - Area 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 an 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 n 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- Area Chart

Related Topics

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 Tutorial

Introduction of JavaFX: The most popular applications called Rich Internet Application are build using the JavaFX. This application can run across many platforms. Various devices such as mobile, computers, and tablets...

4 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX Cylinder

In the JavaFX application, in order to draw a Cylinder, the Cylinder class is used. The Cylinder allows us to form a 3D shape having rectangular faces and a straight...

4 minutes read.

JavaFX Image Input

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

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 Scaling

In the JavaFX application, in order to apply various Scaling effects, we use this class. It has the ability to change the size of the given object. All methods needed...

5 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 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 Arc

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

5 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 - 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 Inner Shadow

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

4 minutes read.

JavaFX Scale Transition

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

4 minutes read.

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

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 Bar Chart

In the JavaFX application, in order to create Bar Chart, the BarChart class is used. The Bar Chart allows us to plot data along different bars to show the scales...

4 minutes read.

JavaFX Path Transition

In the JavaFX application, in order to generate the path transition, we have to apply path transition on any particular shape. It has the ability to traverse the given shape...

3 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.

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.