1 /*
   2  * Copyright (c) 2008, 2015, 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 
  33 package ensemble.samples.charts.scatter.chart;
  34 
  35 
  36 import javafx.application.Application;
  37 import javafx.collections.FXCollections;
  38 import javafx.collections.ObservableList;
  39 import javafx.scene.Parent;
  40 import javafx.scene.Scene;
  41 import javafx.scene.chart.ScatterChart;
  42 import javafx.scene.chart.XYChart;
  43 import javafx.scene.chart.NumberAxis;
  44 import javafx.stage.Stage;
  45 
  46 
  47 /**
  48  * A chart that displays plotted symbols for a series of data points. Useful
  49  * for viewing the distribution of data to see if there is any pattern,
  50  * indicating a correlation.
  51  *
  52  * @sampleName Scatter Chart
  53  * @preview preview.png 
  54  * @see javafx.scene.chart.ScatterChart
  55  * @see javafx.scene.chart.NumberAxis
  56  * @related /Charts/Line/Line Chart
  57  * @related /Charts/Area/Area Chart
  58  * @docUrl https://docs.oracle.com/javafx/2/charts/jfxpub-charts.htm Using JavaFX Charts Tutorial
  59  * @playground chart.data
  60  * @playground - (name="xAxis")
  61  * @playground xAxis.autoRanging
  62  * @playground xAxis.forceZeroInRange
  63  * @playground xAxis.lowerBound (min=-10, max=10, step=0.25)
  64  * @playground xAxis.upperBound (max=20, step=0.25)
  65  * @playground xAxis.tickUnit (max=10, step=0.25)
  66  * @playground xAxis.minorTickCount (max=16)
  67  * @playground xAxis.minorTickLength (max=15)
  68  * @playground xAxis.minorTickVisible
  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  * @playground - (name="yAxis")
  79  * @playground yAxis.autoRanging
  80  * @playground yAxis.forceZeroInRange
  81  * @playground yAxis.lowerBound (min=-5,max=5,step=0.25)
  82  * @playground yAxis.upperBound (max=10,step=0.25)
  83  * @playground yAxis.tickUnit (max=10,step=0.25)
  84  * @playground yAxis.minorTickCount (max=16)
  85  * @playground yAxis.minorTickLength (max=15)
  86  * @playground yAxis.minorTickVisible
  87  * @playground yAxis.animated
  88  * @playground yAxis.label
  89  * @playground yAxis.side
  90  * @playground yAxis.tickLabelFill
  91  * @playground yAxis.tickLabelGap
  92  * @playground yAxis.tickLabelRotation (min=-180,max=180,step=1)
  93  * @playground yAxis.tickLabelsVisible
  94  * @playground yAxis.tickLength
  95  * @playground yAxis.tickMarkVisible
  96  * @playground - (name="chart")
  97  * @playground chart.horizontalGridLinesVisible
  98  * @playground chart.horizontalZeroLineVisible
  99  * @playground chart.verticalGridLinesVisible
 100  * @playground chart.verticalZeroLineVisible
 101  * @playground chart.animated
 102  * @playground chart.legendSide
 103  * @playground chart.legendVisible
 104  * @playground chart.title
 105  * @playground chart.titleSide
 106  * @embedded
 107  */
 108 public class ScatterChartApp extends Application {
 109     
 110     private ScatterChart chart;
 111     private NumberAxis xAxis;
 112     private NumberAxis yAxis;
 113 
 114     public Parent createContent() {
 115         xAxis = new NumberAxis("X-Axis", 0d, 8.0d, 1.0d);
 116         yAxis = new NumberAxis("Y-Axis", 0.0d, 5.0d, 1.0d);
 117         ObservableList<XYChart.Series> data = FXCollections.observableArrayList(
 118             new ScatterChart.Series("Series 1", FXCollections.<ScatterChart.Data>observableArrayList(
 119                 new XYChart.Data(0.2, 3.5),
 120                 new XYChart.Data(0.7, 4.6),
 121                 new XYChart.Data(1.8, 1.7),
 122                 new XYChart.Data(2.1, 2.8),
 123                 new XYChart.Data(4.0, 2.2),
 124                 new XYChart.Data(4.1, 2.6),
 125                 new XYChart.Data(4.5, 2.0),
 126                 new XYChart.Data(6.0, 3.0),
 127                 new XYChart.Data(7.0, 2.0),
 128                 new XYChart.Data(7.8, 4.0)
 129             ))
 130         );
 131         chart = new ScatterChart(xAxis, yAxis, data);
 132         return chart;
 133     }
 134     
 135 
 136     @Override public void start(Stage primaryStage) throws Exception {
 137         primaryStage.setScene(new Scene(createContent()));
 138         primaryStage.show();
 139     }
 140 
 141     /**
 142      * Java main for when running without JavaFX launcher
 143      * @param args command line arguments
 144      */
 145     public static void main(String[] args) {
 146         launch(args);
 147     }
 148 }