Javatpoint Logo
Javatpoint Logo

JavaFX BarChart

In general, A bar chart can be defined as a diagram which uses rectangular bars for the data representation. The length of the bars represents the exact numeric data values plotted on one of the axes. The rectangular bars can be plotted horizontally or vertically on the graph.

In the following image, A bar chart shows the number of students in each branch of engineering. The X-axis is the category axis which shows different branches while the Y-axis is the number axis which shows the number of students in a particular branch.


JavaFX BarChart1

In JavaFX, the class javafx.scene.chart.BarChart represents the Bar Chart. We need to instantiate this class in order to create the bar chart.

Properties

The properties of the class along with the setter methods are described in the following table.

Property Description Setter Method
barGap This is a double type property. It represents the gap between the bars of the same category. setBarGap(Double value)
categoryGap This is a double type property. It represents the gap between the different category. setCategoryGap(Double value)

Constructors

There are the three constructors in the class.

  1. public BarChart(Axis Xaxis, Axis Yaxis) : creates the new instance of BarChart with the specified axis.
  2. public BarChart(Axis Xaxis, Axis Yaxis, ObservableList> data): creates the new instance of BarChart with the specified axis and data.
  3. public BarChart(Axis Xaxis, Axis Yaxis, ObservableList> data, double categoryGap)) : Creates the new instance of BarChart with the specifies axis, data and the category gap.

Example

In the following example, we have shown the conversion between the different currencies and the Dollar.


JavaFX BarChart2





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA