Java Reference
In-Depth Information
StackPane root = new StackPane();
root.getChildren().add(barChart);
primaryStage.setScene(new Scene(root, 400, 250));
primaryStage.show();
}
Once we replace the import for
javafx.scene.chart.ScatterChart
with one for
javafx.scene.chart.
BarChart
, we can build the application and run it. The result is a
BarChart
similar to that shown in Figure
8-11
.
Figure 8-11.
Using
BarChart
for highlighting differences between the values
Although the result indeed shows the differences between the values for each year, it is not very clear because the
bars are rather small. With a total scene width at 400 pixels, there is not much space to render large bars. However,
the
BarChart
API contains methods to define the inner gap between bars and the gap between categories. In our case,
we want a smaller gap between the bars, for example, one pixel. This is done by calling
barChart.setBarGap(1);
Adding this single line of code to the start method and rerunning the application results in the output shown
in Figure
8-12
.
Search WWH ::
Custom Search