Java Reference
In-Depth Information
index for Java, C, and C++ in 2011, and add random values (between -2 and +2) to them for each year until 2020. The
resulting (year, number) pairs for Java constitute the Java Series, and the same holds for C and C++. As a result,
we have three series, each containing 10 pairs.
A major difference between a
PieChart
and an
XYChart
is the presence of an x axis and a y axis in the
XYChart
.
These axes are required when creating an
XYChart
, as can be observed from the following constructor.
XYChart (Axis<X> xAxis, Axis<Y> yAxis)
The
Axis
class is an abstract class extending
Region
(hence also extending
Parent
and
Node
) with two subclasses:
CategoryAxis
and
ValueAxis
. The
CategoryAxis
is used to render labels that are in the
String
format, as can be
observed from the class definition:
public class CategoryAxis extends Axis<java.lang.String>
The
ValueAxis
is used to render data entries that represent a
Number
. It is an abstract class itself, defined as follows.
public abstract class ValueAxis <T extends java.lang.Number> extends Axis<T>
The
ValueAxis
class has one concrete subclass, which is the
NumberAxis
:
public final class NumberAxis extends ValueAxis<java.lang.Number>
The differences between those
Axis
classes will become clear throughout the examples. We now show some
examples of the different
XYChart
implementations, starting with the
ScatterChart
. Some features common to all
XYChart
s are also explained in the section on
ScatterChart
.
■
Because the
Axis
classes extend
Region
, they allow for applying the same Css elements as any other
Regions
. this allows for highly customized
Axis
instances.
Note
Using the ScatterChart
An instance of the
ScatterChart
class is used to render data where each data item is represented as a symbol in a
two-dimensional area. As mentioned in the previous section, we will render a chart containing three series of data,
representing the hypothetical evolution of the TIOBE index for Java, C, and C++. We first show the code of a naive
implementation, and refine that to something more useful.
A Simple Implementation
A first implementation of our application using a
ScatterChart
is shown in Listing 8-5.
Listing 8-5.
First Implementation of Rendering Data in a
ScatterChart
package projavafx ;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
Search WWH ::
Custom Search