JavaFX StackedBarChart

In stacked bar charts, the values of the different groups are displayed on a rectangular bar in the form of a stack. This is mainly used to compare the values of the different groups according to its length plotted on the bar.

In the following image, the population of men and women in the different states, is compared. On the x-axis, the states plotted while, on the y-axis the population is plotted.


JavaFX StackedBarChart1

In JavaFX, the class javafx.scene.chart.StackedBarChart represents the stacked bar chart. We need to instantiate this class to generate a StackedBarChart node.

Properties

The class contains only one property which is described in the following table along with its setter method.

Property Description Setter Method
categoryGap It is a double type property. It represents the gap between the categories of the bar. setCategoryGap(double value)

Constructors

There are the three constructors in the class.

  1. public StackedBarChart(Axis Xaxis, Axis Yaxis) : creates the new instance of stackedbarchart with the specified axis.
  2. public StackedBarChart(Axis Xaxis, Axis Yaxis, ObservableList > data) : creates the new instance of stackedbarchart with the specified axis and data.
  3. public StackedBarChart(Axis Xaxis, Axis Yaxis, ObservableList > data, double categoryGap) : creates the new instance of StackeBarChart with the specified axis, data and categorygap

Example

In the following example, we have shown the comparison between the popularity of two programming languages in each month of a year. The x-axis is a category axis while the y-axis is a number axis. On X-axis, we have plotted the months of a year while on the y-axis we have plotted the number of readers.


JavaFX StackedBarChart2
Next Topicjavafx CSS




Contact US

Email:[email protected]

Stacked Bar Chart
10/30