| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package chartline; |
| |
| import javafx.application.Application; |
| import javafx.collections.FXCollections; |
| import javafx.collections.ObservableList; |
| import javafx.scene.Group; |
| import javafx.scene.Scene; |
| import javafx.scene.chart.LineChart; |
| import javafx.scene.chart.NumberAxis; |
| import javafx.scene.chart.XYChart; |
| import javafx.stage.Stage; |
| |
| /** |
| * A chart in which lines connect a series of data points. Useful for viewing |
| * data trends over time. |
| * |
| * @see javafx.scene.chart.LineChart |
| * @see javafx.scene.chart.Chart |
| * @see javafx.scene.chart.Axis |
| * @see javafx.scene.chart.NumberAxis |
| * @related charts/area/AreaChart |
| * @related charts/scatter/ScatterChart |
| */ |
| public class ChartLine extends Application { |
| |
| private void init(Stage primaryStage) { |
| Group root = new Group(); |
| primaryStage.setScene(new Scene(root)); |
| NumberAxis xAxis = new NumberAxis("Values for X-Axis", 0, 3, 1); |
| NumberAxis yAxis = new NumberAxis("Values for Y-Axis", 0, 3, 1); |
| ObservableList<XYChart.Series<Double,Double>> lineChartData = FXCollections.observableArrayList( |
| new LineChart.Series<Double,Double>("Series 1", FXCollections.observableArrayList( |
| new XYChart.Data<Double,Double>(0.0, 1.0), |
| new XYChart.Data<Double,Double>(1.2, 1.4), |
| new XYChart.Data<Double,Double>(2.2, 1.9), |
| new XYChart.Data<Double,Double>(2.7, 2.3), |
| new XYChart.Data<Double,Double>(2.9, 0.5) |
| )), |
| new LineChart.Series<Double,Double>("Series 2", FXCollections.observableArrayList( |
| new XYChart.Data<Double,Double>(0.0, 1.6), |
| new XYChart.Data<Double,Double>(0.8, 0.4), |
| new XYChart.Data<Double,Double>(1.4, 2.9), |
| new XYChart.Data<Double,Double>(2.1, 1.3), |
| new XYChart.Data<Double,Double>(2.6, 0.9) |
| )) |
| ); |
| LineChart chart = new LineChart(xAxis, yAxis, lineChartData); |
| root.getChildren().add(chart); |
| } |
| |
| @Override public void start(Stage primaryStage) throws Exception { |
| init(primaryStage); |
| primaryStage.show(); |
| } |
| |
| /** |
| * The main() method is ignored in correctly deployed JavaFX |
| * application. main() serves only as fallback in case the |
| * application can not be launched through deployment artifacts, |
| * e.g., in IDEs with limited FX support. NetBeans ignores main(). |
| * @param args the command line arguments |
| */ |
| public static void main(String[] args) { |
| launch(args); |
| } |
| } |