1 /* 2 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. 3 * All rights reserved. Use is subject to license terms. 4 * 5 * This file is available and licensed under the following license: 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the distribution. 16 * - Neither the name of Oracle Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package ensemble.samples.charts.line.chart; 33 34 35 import javafx.application.Application; 36 import javafx.collections.FXCollections; 37 import javafx.collections.ObservableList; 38 import javafx.scene.Parent; 39 import javafx.scene.Scene; 40 import javafx.scene.chart.LineChart; 41 import javafx.scene.chart.XYChart; 42 import javafx.scene.chart.NumberAxis; 43 import javafx.stage.Stage; 44 45 46 /** 47 * A chart in which lines connect a series of data points. Useful for viewing 48 * data trends over time. 49 * 50 * @sampleName Line Chart 51 * @preview preview.png 52 * @see javafx.scene.chart.LineChart 53 * @see javafx.scene.chart.NumberAxis 54 * @related /Charts/Area/Area Chart 55 * @related /Charts/Scatter/Scatter Chart 56 * @docUrl http://docs.oracle.com/javafx/2/charts/jfxpub-charts.htm Using JavaFX Charts Tutorial 57 * @playground chart.data 58 * 59 * @playground - (name="xAxis") 60 * @playground xAxis.autoRanging 61 * @playground xAxis.forceZeroInRange 62 * @playground xAxis.lowerBound (min=-10,max=10,step=0.2) 63 * @playground xAxis.upperBound (max=10,step=0.2) 64 * @playground xAxis.tickUnit (max=3,step=0.2) 65 * @playground xAxis.minorTickCount (max=16) 66 * @playground xAxis.minorTickLength (max=15) 67 * @playground xAxis.minorTickVisible 68 * 69 * @playground xAxis.animated 70 * @playground xAxis.label 71 * @playground xAxis.side 72 * @playground xAxis.tickLabelFill 73 * @playground xAxis.tickLabelGap 74 * @playground xAxis.tickLabelRotation (min=-180,max=180,step=1) 75 * @playground xAxis.tickLabelsVisible 76 * @playground xAxis.tickLength 77 * @playground xAxis.tickMarkVisible 78 * 79 * @playground - (name="yAxis") 80 * @playground yAxis.autoRanging 81 * @playground yAxis.forceZeroInRange 82 * @playground yAxis.lowerBound (min=-5,max=5,step=0.2) 83 * @playground yAxis.upperBound (max=10,step=0.2) 84 * @playground yAxis.tickUnit (max=3,step=0.2) 85 * @playground yAxis.minorTickCount (max=16) 86 * @playground yAxis.minorTickLength (max=15) 87 * @playground yAxis.minorTickVisible 88 * 89 * @playground yAxis.animated 90 * @playground yAxis.label 91 * @playground yAxis.side 92 * @playground yAxis.tickLabelFill 93 * @playground yAxis.tickLabelGap 94 * @playground yAxis.tickLabelRotation (min=-180,max=180,step=1) 95 * @playground yAxis.tickLabelsVisible 96 * @playground yAxis.tickLength 97 * @playground yAxis.tickMarkVisible 98 * 99 * @playground - (name="chart") 100 * @playground chart.horizontalGridLinesVisible 101 * @playground chart.horizontalZeroLineVisible 102 * @playground chart.verticalGridLinesVisible 103 * @playground chart.verticalZeroLineVisible 104 * 105 * @playground chart.animated 106 * @playground chart.legendSide 107 * @playground chart.legendVisible 108 * @playground chart.title 109 * @playground chart.titleSide 110 * @embedded 111 */ 112 public class LineChartApp extends Application { 113 114 private LineChart chart; 115 private NumberAxis xAxis; 116 private NumberAxis yAxis; 117 118 public Parent createContent() { 119 xAxis = new NumberAxis("Values for X-Axis", 0, 3, 1); 120 yAxis = new NumberAxis("Values for Y-Axis", 0, 3, 1); 121 ObservableList<XYChart.Series<Double,Double>> lineChartData = FXCollections.observableArrayList( 122 new LineChart.Series<>("Series 1", FXCollections.observableArrayList( 123 new XYChart.Data<>(0.0, 1.0), 124 new XYChart.Data<>(1.2, 1.4), 125 new XYChart.Data<>(2.2, 1.9), 126 new XYChart.Data<>(2.7, 2.3), 127 new XYChart.Data<>(2.9, 0.5) 128 )), 129 new LineChart.Series<>("Series 2", FXCollections.observableArrayList( 130 new XYChart.Data<>(0.0, 1.6), 131 new XYChart.Data<>(0.8, 0.4), 132 new XYChart.Data<>(1.4, 2.9), 133 new XYChart.Data<>(2.1, 1.3), 134 new XYChart.Data<>(2.6, 0.9) 135 )) 136 ); 137 chart = new LineChart(xAxis, yAxis, lineChartData); 138 return chart; 139 } 140 141 @Override public void start(Stage primaryStage) throws Exception { 142 primaryStage.setScene(new Scene(createContent())); 143 primaryStage.show(); 144 } 145 146 /** 147 * Java main for when running without JavaFX launcher 148 * @param args command line arguments 149 */ 150 public static void main(String[] args) { 151 launch(args); 152 } 153 154 }