Java Reference
In-Depth Information
StackPane root = new StackPane();
root.getChildren().add(lineChart);
primaryStage.setScene(new Scene(root, 400, 250));
primaryStage.show();
}
Running this application gives output like that shown in Figure 8-10 .
Figure 8-10. Using a LineChart for displaying trends
Most of the functionality available for the ScatterChart is also available for the LineChart . Changing the location
of the legend, adding or removing a title, and using a NumberAxis instead of a CategoryAxis are possible using the
LineChart .
Using the BarChart
A BarChart is capable of rendering the same data as a ScatterChart and a LineChart , but it looks different. In a
BarChart , the focus is often more on showing the relative differences between the different series for a given category.
In our case, that means that we focus on the differences between the values for Java, C, and C++.
Again, we do not need to modify the method that returns our data. Indeed, a BarChart requires a CategoryAxis
for its xAxis , and we already modified the getChartData() method to return an ObservableList containing
XYChart.Series<String, double> . Starting from Listing 8-6, we change only the occurrences of ScatterChart to
BarChart and we obtain Listing 8-8.
Listing 8-8. Using a BarChart Instead of a ScatterChart
public void start(Stage primaryStage) {
CategoryAxis xAxis = new CategoryAxis();
NumberAxis yAxis = new NumberAxis();
BarChart barChart = new BarChart(xAxis, yAxis);
barChart.setData(getChartData());
barChart.setTitle("speculations");
primaryStage.setTitle("BarChart example");
 
Search WWH ::




Custom Search