AreaChart(Axis < X > xAxis, Axis < Y > yAxis, ObservableList < XYChart.Series < X , Y >> data) constructor from AreaChart has the following syntax.
public AreaChart(Axis<X> xAxis,
Axis<Y> yAxis,
ObservableList<XYChart.Series<X, Y> data)
In the following code shows how to use AreaChart.AreaChart(Axis < X > xAxis, Axis < Y > yAxis, ObservableList < XYChart.Series < X , Y >> data) constructor.
// w w w .j a v a 2s .c om 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; public class Main extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { CategoryAxis xAxis = new CategoryAxis(); NumberAxis yAxis = new NumberAxis(); AreaChart areaChart = new AreaChart(xAxis, yAxis,getChartData()); areaChart.setTitle("speculations"); primaryStage.setTitle("AreaChart example"); StackPane root = new StackPane(); root.getChildren().add(areaChart); primaryStage.setScene(new Scene(root, 400, 250)); primaryStage.show(); } private ObservableList<XYChart.Series<String, Double>> getChartData() { double aValue = 1.56; double bValue = 1.06; ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList(); Series<String, Double> aSeries = new Series<String, Double>(); Series<String, Double> bSeries = new Series<String, Double>(); aSeries.setName("a"); bSeries.setName("b"); for (int i = 2011; i < 2021; i++) { aSeries.getData().add(new XYChart.Data(Integer.toString(i), aValue)); aValue = aValue + Math.random() - .5; bSeries.getData().add(new XYChart.Data(Integer.toString(i), bValue)); bValue = bValue + Math.random() - .5; } answer.addAll(aSeries, bSeries); return answer; } }