Java Reference
In-Depth Information
By default, a PieChart uses the default colors defined in the caspian style sheet. The first slice is filled with
default-color0 , the second slice with default-color1 , and so on. The easiest way to change the color of the different
slices is by overriding the definitions of the default color. In our style sheet, this is done by
.default-color0.chart-pie {
-fx-pie-color: blue;
}
The same can be done for the other slices.
If you run the example without the other parts of the CSS, you would notice the chart itself is rather small, and the
size of the labels takes too much space. Therefore, we modify the font size of the labels as follows:
.chart-pie-label {
-fx-font-size:9px;
}
Also, we decrease the padding in the chart area:
.chart-content {
-fx-padding:1;
}
Finally, we change the background and the stroke of the legend. This is achieved by overriding the chart-legend
class as follows.
.chart-legend {
-fx-background-color: #f0e68c;
-fx-border-color: #696969;
-fx-border-width:1;
}
Again, we refer the reader to http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/
css-styles.htm for more information about using CSS with JavaFX charts.
Using the XYChart
The XYChart class is an abstract class with seven direct known subclasses. The difference between these classes and
the PieChart class is that an XYChart has two axes and an optional alternativeColumn or alternativeRow . This
translates to the following list of additional properties on an XYChart .
BooleanProperty alternativeColumnFillVisible
BooleanProperty alternativeRowFillVisible
ObjectProperty<ObservableList<XYChart.Series<X,Y>>>data
BooleanProperty horizontalGridLinesVisible
BooleanProperty horizontalZeroLineVisible
BooleanProperty verticalGridLinesVisible
BooleanProperty verticalZeroLineVisible
Data in an XYChart are ordered in series. How these series are rendered is specific to the implementation of the
subclass of XYChart . In general, a single element in a series contains a number of pairs. The following examples use
a hypothetical projection of market share of three programming languages in the future. We start with the TIOBE
 
Search WWH ::




Custom Search