Java Reference
In-Depth Information
Figure 8-5. Using CSS to style the PieChart
We now go over the changes we made. Before we go over the individual changes in detail, we show how we
include the CSS with our application. This is achieved by adding the style sheet to the scene, which is done as follows.
scene.getStylesheets().add("/chartappstyle.css");
The file containing the style sheet, chartappstyle.css , must be in the classpath when the application is running.
In Listing 8-2, we set the clockwise configuration using
pieChart.setClockwise(false)
We removed that line from the code in Listing 8-3, and instead defined the -fx-clockwise property on the chart
class in the style sheet:
.chart {
-fx-clockwise: false;
-fx-pie-label-visible: true;
-fx-label-line-length: 5;
-fx-start-angle: 90;
-fx-legend-side: right;
}
In that same .chart class definition, we make the labels on the pie visible by setting the -fx-pie-label-visible
property to true, and we specify the length of the lines for each label to be 5.
Also, we rotate the whole pie by 90 degrees, which is achieved by defining the -fx-start-angle property. The
labels are now defined in the style sheet, and we remove the corresponding definition from the code by omitting
the following line.
pieChart.setLabelsVisible(false)
To make sure the legend will appear at the right side of the chart, we specify the -fx-legend-side property.
 
Search WWH ::




Custom Search