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.area.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.AreaChart;
  42 import javafx.scene.chart.NumberAxis;
  43 import javafx.stage.Stage;
  44 
  45 
  46 /**
  47  * A chart that fills in the area between a line of data points and the axes.
  48  * Good for comparing accumulated totals over time.
  49  *
  50  * @sampleName Area Chart
  51  * @preview preview.png
  52  * @see javafx.scene.chart.AreaChart
  53  * @see javafx.scene.chart.NumberAxis
  54  * @related /Charts/Line/Line 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  * @playground - (name="xAxis")
  59  * @playground xAxis.autoRanging
  60  * @playground xAxis.forceZeroInRange
  61  * @playground xAxis.lowerBound (min=-10, max=10, step=1)
  62  * @playground xAxis.upperBound (min=-10, max=10, step=1)
  63  * @playground xAxis.tickUnit (max=10, step=0.5)
  64  * @playground xAxis.minorTickCount (max=16)
  65  * @playground xAxis.minorTickLength (max=15)
  66  * @playground xAxis.minorTickVisible
  67  * @playground xAxis.animated
  68  * @playground xAxis.label
  69  * @playground xAxis.side
  70  * @playground xAxis.tickLabelFill
  71  * @playground xAxis.tickLabelGap
  72  * @playground xAxis.tickLabelRotation (min=-180,max=180,step=1)
  73  * @playground xAxis.tickLabelsVisible
  74  * @playground xAxis.tickLength
  75  * @playground xAxis.tickMarkVisible
  76  * @playground - (name="yAxis")
  77  * @playground yAxis.autoRanging
  78  * @playground yAxis.forceZeroInRange
  79  * @playground yAxis.lowerBound (min=-10, max=10, step=1)
  80  * @playground yAxis.upperBound (min=-10, max=10, step=1)
  81  * @playground yAxis.tickUnit (max=10, step=1)
  82  * @playground yAxis.minorTickCount (max=16)
  83  * @playground yAxis.minorTickLength (max=15)
  84  * @playground yAxis.minorTickVisible
  85  * @playground yAxis.animated
  86  * @playground yAxis.label
  87  * @playground yAxis.side
  88  * @playground yAxis.tickLabelFill
  89  * @playground yAxis.tickLabelGap
  90  * @playground yAxis.tickLabelRotation (min=-180,max=180)
  91  * @playground yAxis.tickLabelsVisible
  92  * @playground yAxis.tickLength
  93  * @playground yAxis.tickMarkVisible
  94  * @playground - (name="chart")
  95  * @playground chart.horizontalGridLinesVisible
  96  * @playground chart.horizontalZeroLineVisible
  97  * @playground chart.verticalGridLinesVisible
  98  * @playground chart.verticalZeroLineVisible
  99  * @playground chart.animated
 100  * @playground chart.legendSide
 101  * @playground chart.legendVisible
 102  * @playground chart.title
 103  * @playground chart.titleSide
 104  * @embedded 
 105  */
 106 public class AreaChartApp extends Application {
 107 
 108     private AreaChart chart;
 109     private NumberAxis xAxis;
 110     private NumberAxis yAxis;
 111 
 112     public Parent createContent() {
 113         xAxis = new NumberAxis();
 114         xAxis.setLabel("X Values");
 115         yAxis = new NumberAxis();
 116         yAxis.setLabel("Y Values");
 117         ObservableList<AreaChart.Series> areaChartData = FXCollections.observableArrayList(
 118                 new AreaChart.Series("Series 1",FXCollections.observableArrayList(
 119                     new AreaChart.Data(0,4),
 120                     new AreaChart.Data(2,5),
 121                     new AreaChart.Data(4,4),
 122                     new AreaChart.Data(6,2),
 123                     new AreaChart.Data(8,6),
 124                     new AreaChart.Data(10,8)
 125                 )),
 126                 new AreaChart.Series("Series 2", FXCollections.observableArrayList(
 127                     new AreaChart.Data(0,8),
 128                     new AreaChart.Data(2,2),
 129                     new AreaChart.Data(4,9),
 130                     new AreaChart.Data(6,7),
 131                     new AreaChart.Data(8,5),
 132                     new AreaChart.Data(10,7)
 133                 )),
 134                 new AreaChart.Series("Series 3", FXCollections.observableArrayList(
 135                     new AreaChart.Data(0,2),
 136                     new AreaChart.Data(2,5),
 137                     new AreaChart.Data(4,8),
 138                     new AreaChart.Data(6,6),
 139                     new AreaChart.Data(8,9),
 140                     new AreaChart.Data(10,7)
 141                 ))
 142         );
 143         chart = new AreaChart(xAxis, yAxis, areaChartData);
 144         return chart;
 145     }
 146     
 147    
 148     @Override public void start(Stage primaryStage) throws Exception {
 149         primaryStage.setScene(new Scene(createContent()));
 150         primaryStage.show();
 151     }
 152 
 153     /**
 154      * Java main for when running without JavaFX launcher
 155      * @param args command line arguments
 156      */
 157     public static void main(String[] args) {
 158         launch(args);
 159     }
 160 }