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 
  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 http://docs.oracle.com/javafx/2/charts/jfxpub-charts.htm Using JavaFX Charts Tutorial
  59  * @playground chart.data
  60  * 
  61  * @playground - (name="xAxis")
  62  * @playground xAxis.autoRanging
  63  * @playground xAxis.forceZeroInRange
  64  * @playground xAxis.lowerBound (min=-10, max=10, step=0.25)
  65  * @playground xAxis.upperBound (max=20, step=0.25)
  66  * @playground xAxis.tickUnit (max=10, step=0.25)
  67  * @playground xAxis.minorTickCount (max=16)
  68  * @playground xAxis.minorTickLength (max=15)
  69  * @playground xAxis.minorTickVisible
  70  * 
  71  * @playground xAxis.animated
  72  * @playground xAxis.label
  73  * @playground xAxis.side
  74  * @playground xAxis.tickLabelFill
  75  * @playground xAxis.tickLabelGap
  76  * @playground xAxis.tickLabelRotation (min=-180,max=180,step=1)
  77  * @playground xAxis.tickLabelsVisible
  78  * @playground xAxis.tickLength
  79  * @playground xAxis.tickMarkVisible
  80  * 
  81  * @playground - (name="yAxis")
  82  * @playground yAxis.autoRanging
  83  * @playground yAxis.forceZeroInRange
  84  * @playground yAxis.lowerBound (min=-5,max=5,step=0.25)
  85  * @playground yAxis.upperBound (max=10,step=0.25)
  86  * @playground yAxis.tickUnit (max=10,step=0.25)
  87  * @playground yAxis.minorTickCount (max=16)
  88  * @playground yAxis.minorTickLength (max=15)
  89  * @playground yAxis.minorTickVisible
  90  * 
  91  * @playground yAxis.animated
  92  * @playground yAxis.label
  93  * @playground yAxis.side
  94  * @playground yAxis.tickLabelFill
  95  * @playground yAxis.tickLabelGap
  96  * @playground yAxis.tickLabelRotation (min=-180,max=180,step=1)
  97  * @playground yAxis.tickLabelsVisible
  98  * @playground yAxis.tickLength
  99  * @playground yAxis.tickMarkVisible
 100  * 
 101  * @playground - (name="chart")
 102  * @playground chart.horizontalGridLinesVisible
 103  * @playground chart.horizontalZeroLineVisible
 104  * @playground chart.verticalGridLinesVisible
 105  * @playground chart.verticalZeroLineVisible
 106  * 
 107  * @playground chart.animated
 108  * @playground chart.legendSide
 109  * @playground chart.legendVisible
 110  * @playground chart.title
 111  * @playground chart.titleSide
 112  * @embedded
 113  */
 114 public class ScatterChartApp extends Application {
 115     
 116     private ScatterChart chart;
 117     private NumberAxis xAxis;
 118     private NumberAxis yAxis;
 119 
 120     public Parent createContent() {
 121         xAxis = new NumberAxis("X-Axis", 0d, 8.0d, 1.0d);
 122         yAxis = new NumberAxis("Y-Axis", 0.0d, 5.0d, 1.0d);
 123         ObservableList<XYChart.Series> data = FXCollections.observableArrayList(
 124             new ScatterChart.Series("Series 1", FXCollections.<ScatterChart.Data>observableArrayList(
 125                 new XYChart.Data(0.2, 3.5),
 126                 new XYChart.Data(0.7, 4.6),
 127                 new XYChart.Data(1.8, 1.7),
 128                 new XYChart.Data(2.1, 2.8),
 129                 new XYChart.Data(4.0, 2.2),
 130                 new XYChart.Data(4.1, 2.6),
 131                 new XYChart.Data(4.5, 2.0),
 132                 new XYChart.Data(6.0, 3.0),
 133                 new XYChart.Data(7.0, 2.0),
 134                 new XYChart.Data(7.8, 4.0)
 135             ))
 136         );
 137         chart = new ScatterChart(xAxis, yAxis, data);
 138         return chart;
 139     }
 140     
 141 
 142     @Override public void start(Stage primaryStage) throws Exception {
 143         primaryStage.setScene(new Scene(createContent()));
 144         primaryStage.show();
 145     }
 146 
 147     /**
 148      * Java main for when running without JavaFX launcher
 149      * @param args command line arguments
 150      */
 151     public static void main(String[] args) {
 152         launch(args);
 153     }
 154 }