Java Reference
In-Depth Information
Figure 8-15.
Rendering area plots using
AreaChart
Using the BubbleChart
The last implementation of the
XYChart
is a special one. The
BubbleChart
does not contain properties that are not
already on the
XYChart
class, but it is the only direct implementation in the current JavaFX
Chart
API that uses the
additional parameter on the
XYChart.Data
class.
We first modify the code in Listing 8-6 to use the
BubbleChart
instead of the
ScatterChart
. Because by default,
bubbles are stretched when the span on the
xAxis
is much different from the span on the
yAxis
, we do not use years,
but a tenth of a year as the value on the
xAxis
. Doing so, we have a span of 100 units on the
xAxis
(10 years) compared
with a span of about 30 units on the
yAxis
. This is also more or less the ratio between the width and the height of our
chart. As a consequence, the bubbles are relatively circular.
Listing 8-11 contains the code for rendering a
BubbleChart
.
Listing 8-11.
Using the
BubbleChart
package projavafx;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.*;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.StringConverter;
public class ChartApp10 extends Application {
public static void main(String[] args) {
launch(args);
}
Search WWH ::
Custom Search