Java Reference
In-Depth Information
Figure 8-3. Rendering the TIOBE index in a PieChart
With only a limited amount of code, we can render data in a PieChart . Before we make modifications to this
example, we explain the different parts.
The code required for setting up the Application, the Stage, and the Scene is covered in Chapter 1. A PieChart
extends a Node , so we can easily add it to the scene graph. The first two lines of code in the start method create the
PieChart , and add the required data to it:
PieChart pieChart = new PieChart();
pieChart.setData(getChartData());
The data, which are of type ObservableList<PieChart.Data> are obtained from the getChartData() method
and for our example, it contains static data. As the return type of the getChartData() method specifies, the returned
data are an ObservableList of PieChart.Data .
An instance of PieChart.Data , which is a nested class of PieChart , contains the information required to draw
one slice of the pie. PieChart.Data has a constructor that takes the name of the slice and its value:
PieChart.Data(String name, double value)
We use this constructor to create data elements containing the name of a programming language and its score in
the TIOBE index.
new PieChart.Data("java", 17.56)
We then add those elements to the ObservableList<PieChart.Data> we need to return.
 
Search WWH ::




Custom Search