JavaFX Charts - JavaFX

What is JavaFX Charts?

In popular, a chart is a graphical representation of records. there are various types of charts to symbolize information including Bar Chart, Pie Chart, Line Chart, Scatter Chart, etc.

JavaFX presents assist for various Pie Charts and XY Charts. The charts which can be represented on an XY–plane consist of AreaChart, BarChart, BubbleChart, LineChart, ScatterChart, StackedAreaChart, StackedBarChart, etc.

Every chart is represented by using a class and these types of charts belongs to the package javafx.scene.chart. The class named Chart is the base class of all the charts in JavaFX and the XYChart is base class of all the ones charts that are drawn on the XY–plane.

JavaFX - Charts

Creating a Chart

To create a chart, you want to −

  • Define the axis of the chart
  • Instantiate the respective class
  • Prepare and pass data to the chart

Instantiating the Respective class

To create a chart, instantiate its respective class. for example, if you want to create a line chart, you need to instantiate the class named Line as follows –

As observed in the above code, at the same time as instantiating, you need to pass objects representing the X and Y axis of the chart respectively.

Defining the Axis

In general, the axis of the charts may be represented by way of −

  • Numbers together with population, Age and
  • Categories including Days in a week, countries.

In JavaFX, an axis is an summary class representing X or Y axis. It has subclasses to define each type of axis, specifically CategoryAxis and NumberAxis as proven in the following diagram –

JavaFX - Charts


Category Axis − through instantiating this class, you may define (create) an X or Y axis along which every value represents a category. you may outline a category axis through instantiating this class as shown below –

To this axis, you need set the list of categories and label to the axis as shown below –

NumberAxis − through instantiating this class, you can outline (create) an X or Y axis along which each value represents a Numerical value. you may use any number type with this Axis, long, Double, BigDecimal, etc. you may define various axis through instantiating this class as follows –

Passing Data to XY Charts

All the XY charts are represented along the XY plane. to plot a set of factors in a chart, we need to specify a sequence of XY coordinates.

The<XY> class of the javafx.scene.chart package is a category using which, you can send information to a chart. This class holds an observable list of named collection. you may get this listing the use of the getData() technique of XYChart.series class as shown below –

Where, series is the object of the XYChart.Series class. You can add data to this list using the add() method as follows −

These two lines can be written together as shown below –

The following table gives a description of various charts (classes) provided by JavaFX –

S.No

Chart & Description

1

Pie Chart

A pie-chart is a representation of values as slices of a circle with different colors. These slices are labeled and the values corresponding to each slice is represented in the chart.

In JavaFX, a pie chart is represented by a class namedPieChart. This class belongs to the packagejavafx.scene.chart.

2

Line Chart

A line chart or line graph displays information as a series of data points (markers) connected by straight line segments. Line Chart shows how the data changes at equal time frequency.

In JavaFX, a line chart is represented by a class namedLineChart. This class belongs to the packagejavafx.scene.chart. By instantiating this class, you can create a LineChart node in JavaFX.

3

Area Chart

Area charts are used to draw area based charts. It plots the area between the given series of points and the axis. In general, this chart is used to compare two quantities.

In JavaFX, an Area chart is represented by a class namedAreaChart. This class belongs to the packagejavafx.scene.chart. By instantiating this class, you can create a AreaChart node in JavaFX.

4

Bar Chart

A bar chart is used to represent grouped data using rectangular bars. The length of these bars depicts the values. The bars in the bar chart can be plotted vertically or horizontally.

In JavaFX, a Bar chart is represented by a class namedBarChart. This class belongs to the packagejavafx.scene.chart. By instantiating this class, you can create a BarChart node in JavaFX.

5

Bubble Chart

A bubble chart is used to plat three-dimensional data. The third dimension will be represented by the size (radius) of the bubble.

In JavaFX, a Bubble chart is represented by a class namedBubbleChart. This class belongs to the packagejavafx.scene.chart. By instantiating this class, you can create a BubbleChart node in JavaFX.

6

Scatter Chart

A scatterplot is a type of graph which uses values from two variables plotted in a Cartesian plane. It is usually used to find out the relationship between two variables.

In JavaFX, a Scatter chart is represented by a class named ScatterChart. This class belongs to the package javafx.scene.chart. By instantiating this class, you can create a ScatterChart node in JavaFX.

7

Stacked Area Chart

In JavaFX, a Stacked Area chart is represented by a class named StackedAreaChart.This class belongs to the packagejavafx.scene.chart. By instantiating this class, you can create an StackedAreaChart node in JavaFX.

8

Stacked Bar Chart

In JavaFX, a Stacked Bar chart is represented by a class named StackedBarChart.This class belongs to the packagejavafx.scene.chart. By instantiating this class, you can create a StackedBarChart node in JavaFX.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JavaFX Topics