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.area.curvefitted;
  33 
  34 import javafx.application.Application;
  35 import javafx.scene.Parent;
  36 import javafx.scene.Scene;
  37 import javafx.scene.chart.NumberAxis;
  38 import javafx.scene.chart.XYChart;
  39 import javafx.stage.Stage;
  40 
  41 /**
  42  * An area chart that demonstrates curve fitting. Styling is done through CSS.
  43  *
  44  * @sampleName Curve-Fitted Area Chart
  45  * @preview preview.png
  46  * @see javafx.scene.chart.AreaChart
  47  * @see javafx.scene.chart.NumberAxis
  48  * @related /Charts/Area/Area Chart
  49  * @docUrl http://docs.oracle.com/javafx/2/charts/jfxpub-charts.htm Using JavaFX Charts Tutorial
  50  * @playground chart.data
  51  * 
  52  * @playground - (name="xAxis")
  53  * @playground xAxis.autoRanging
  54  * @playground xAxis.forceZeroInRange
  55  * @playground xAxis.lowerBound (min=-10000,max=10000,step=1)
  56  * @playground xAxis.upperBound (min=-10000,max=10000,step=1)
  57  * @playground xAxis.tickUnit (max=10000,step=1)
  58  * @playground xAxis.minorTickCount (max=16)
  59  * @playground xAxis.minorTickLength (max=15)
  60  * @playground xAxis.minorTickVisible
  61  * 
  62  * @playground xAxis.animated
  63  * @playground xAxis.side
  64  * @playground xAxis.tickLabelFill
  65  * @playground xAxis.tickLabelGap
  66  * @playground xAxis.tickLabelRotation (min=-180,max=180,step=1)
  67  * @playground xAxis.tickLabelsVisible
  68  * @playground xAxis.tickLength
  69  * @playground xAxis.tickMarkVisible
  70  * 
  71  * @playground - (name="yAxis")
  72  * @playground yAxis.autoRanging
  73  * @playground yAxis.forceZeroInRange
  74  * @playground yAxis.lowerBound (min=-1000, max=1000,step=1)
  75  * @playground yAxis.upperBound (min=-1000, max=2000,step=1)
  76  * @playground yAxis.tickUnit (max=1000,step=1)
  77  * @playground yAxis.minorTickCount (max=16)
  78  * @playground yAxis.minorTickLength (max=15)
  79  * @playground yAxis.minorTickVisible
  80  * 
  81  * @playground yAxis.animated
  82  * @playground yAxis.side
  83  * @playground yAxis.tickLabelFill
  84  * @playground yAxis.tickLabelGap
  85  * @playground yAxis.tickLabelRotation (min=-180,max=180,step=1)
  86  * @playground yAxis.tickLabelsVisible
  87  * @playground yAxis.tickLength
  88  * @playground yAxis.tickMarkVisible
  89  * 
  90  * @playground - (name="chart")
  91  * @playground chart.horizontalGridLinesVisible
  92  * @playground chart.horizontalZeroLineVisible
  93  * @playground chart.verticalGridLinesVisible
  94  * @playground chart.verticalZeroLineVisible
  95  * 
  96  * @playground chart.animated
  97  * @playground chart.legendSide
  98  * @playground chart.legendVisible
  99  * @playground chart.title
 100  * @playground chart.titleSide
 101  */
 102 public class CurveFittedAreaChartApp extends Application {
 103     
 104     private CurveFittedAreaChart chart;
 105     private NumberAxis xAxis;
 106     private NumberAxis yAxis;
 107 
 108     public Parent createContent() {
 109         xAxis = new NumberAxis(0, 10000, 2500);
 110         yAxis = new NumberAxis(0, 1000, 200);
 111         chart = new CurveFittedAreaChart(xAxis, yAxis);
 112         chart.setLegendVisible(false);
 113         chart.setHorizontalGridLinesVisible(false);
 114         chart.setVerticalGridLinesVisible(false);
 115         chart.setAlternativeColumnFillVisible(false);
 116         chart.setAlternativeRowFillVisible(false);
 117         final XYChart.Series<Number, Number> series = new XYChart.Series<>();
 118         series.getData().addAll(
 119                 new XYChart.Data<Number, Number>(0, 950),
 120                 new XYChart.Data<Number, Number>(2000, 100),
 121                 new XYChart.Data<Number, Number>(5000, 200),
 122                 new XYChart.Data<Number, Number>(7500, 180),
 123                 new XYChart.Data<Number, Number>(10000, 100));
 124         chart.getData().add(series);
 125         String curveFittedChartCss = CurveFittedAreaChartApp.class.getResource("CurveFittedAreaChart.css").toExternalForm();
 126         chart.getStylesheets().add(curveFittedChartCss);
 127         return chart;
 128     }
 129    
 130     @Override public void start(Stage primaryStage) throws Exception {
 131         primaryStage.setResizable(false);
 132         primaryStage.setScene(new Scene(createContent()));
 133         primaryStage.show();
 134     }
 135 
 136     /**
 137      * Java main for when running without JavaFX launcher
 138      * @param args command line arguments
 139      */
 140     public static void main(String[] args) {
 141         launch(args);
 142     }
 143 }