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