Creating stacked graphs
An area chart depicts information by allocating more space for larger values. By stacking area charts on top of each other we create a stacked graph, sometimes called a stream graph. However, stacked graphs do not work well with negative values and cannot be used for data where summation does not make sense, such as with temperatures. If too many graphs are stacked, then it can become difficult to interpret.
Next, we will show how to create a stacked bar chart. The stackedGraphExample
method contains the code to create the bar chart. We start with familiar code to set the title and labels. However, for the X axis, the setCategories
method FXCollections
.<String>observableArrayList
instance is used to set the categories. The argument of this constructor is an array of strings created by the Arrays
class's asList
method and the names of the countries:
public void stackedGraphExample(Stage stage) { stage.setTitle("Stacked Bar Chart"); final StackedBarChart...