Java Reference
In-Depth Information
Figure 8-4.
The output of the modified PieChart example
Changing a few lines of code results in output that looks very different. We go over the changes we made in a bit
more detail. First, we added a title to the chart. That was done using the call
pieChart.setTitle("Tiobe index");
We could also have used the
titleProperty
:
pieChart.titleProperty().set("Tiobe index");
Both approaches result in the same output.
■
the upcoming modifications could also be done using the same patterns. We only document the approach with
setter methods, but it is easy to replace this with a property-based approach.
Note
The next line of code in our modified example changes the location of the legend:
pieChart.setLegendSide(Side.LEFT);
When the
legendSide
is not specified, the legend is shown at the default location, which is below the chart. The
title
and the
legendSide
are both properties that belong to the abstract
Chart
class. As a consequence, they can be
set on any chart. The next line in our modified example modifies a property that is specific to a
PieChart
:
pieChart.setClockwise(false);
By default, the slices in a
PieChart
are rendered clockwise. By setting this property to false, the slices are
rendered counterclockwise. We also disabled showing the labels in the
PieChart
. The labels are still shown in the
legend, but they do not point to the individual slices anymore. This is achieved by the following line of code:
pieChart.setLabelsVisible(false);
Search WWH ::
Custom Search