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.line.category;
  33 
  34 
  35 import javafx.application.Application;
  36 import javafx.scene.Parent;
  37 import javafx.scene.Scene;
  38 import javafx.scene.chart.CategoryAxis;
  39 import javafx.scene.chart.LineChart;
  40 import javafx.scene.chart.NumberAxis;
  41 import javafx.scene.chart.XYChart;
  42 import javafx.stage.Stage;
  43 
  44 
  45 /**
  46  * A line chart demonstrating a CategoryAxis implementation.
  47  *
  48  * @sampleName Category Line Chart
  49  * @preview preview.png
  50  * @see javafx.scene.chart.CategoryAxis
  51  * @see javafx.scene.chart.LineChart
  52  * @see javafx.scene.chart.NumberAxis
  53  * @docUrl http://docs.oracle.com/javafx/2/charts/jfxpub-charts.htm Using JavaFX Charts Tutorial
  54  * @playground chart.data
  55  * 
  56  * @playground - (name="xAxis")
  57  * @playground xAxis.autoRanging
  58  * @playground xAxis.gapStartAndEnd
  59  * @playground xAxis.startMargin
  60  * @playground xAxis.endMargin
  61  * 
  62  * @playground xAxis.animated
  63  * @playground xAxis.label
  64  * @playground xAxis.side
  65  * @playground xAxis.tickLabelFill
  66  * @playground xAxis.tickLabelGap
  67  * @playground xAxis.tickLabelRotation (min=-180,max=180,step=1)
  68  * @playground xAxis.tickLabelsVisible
  69  * @playground xAxis.tickLength
  70  * @playground xAxis.tickMarkVisible
  71  * 
  72  * @playground - (name="yAxis")
  73  * @playground yAxis.autoRanging
  74  * @playground yAxis.forceZeroInRange
  75  * @playground yAxis.lowerBound (min=-100,step=1)
  76  * @playground yAxis.upperBound (max=200,step=1)
  77  * @playground yAxis.tickUnit (step=1)
  78  * @playground yAxis.minorTickCount (max=16)
  79  * @playground yAxis.minorTickLength (max=15)
  80  * @playground yAxis.minorTickVisible
  81  * 
  82  * @playground yAxis.animated
  83  * @playground yAxis.label
  84  * @playground yAxis.side
  85  * @playground yAxis.tickLabelFill
  86  * @playground yAxis.tickLabelGap
  87  * @playground yAxis.tickLabelRotation (min=-180,max=180,step=1)
  88  * @playground yAxis.tickLabelsVisible
  89  * @playground yAxis.tickLength
  90  * @playground yAxis.tickMarkVisible
  91  * 
  92  * @playground - (name="chart")
  93  * @playground chart.horizontalGridLinesVisible
  94  * @playground chart.horizontalZeroLineVisible
  95  * @playground chart.verticalGridLinesVisible
  96  * @playground chart.verticalZeroLineVisible
  97  * 
  98  * @playground chart.animated
  99  * @playground chart.legendSide
 100  * @playground chart.legendVisible
 101  * @playground chart.title
 102  * @playground chart.titleSide
 103  */
 104 public class CategoryLineChartApp extends Application {
 105 
 106     private static final String[] CATEGORIES = {"Alpha", "Beta", "RC1", "RC2", "1.0", "1.1"};
 107     private LineChart<String, Number> chart;
 108     private CategoryAxis xAxis;
 109     private NumberAxis yAxis;
 110 
 111     public Parent createContent() {
 112         xAxis = new CategoryAxis();
 113         yAxis = new NumberAxis();
 114         chart = new LineChart<>(xAxis, yAxis);
 115         // setup chart
 116         chart.setTitle("LineChart with Category Axis");
 117         xAxis.setLabel("X Axis");
 118         yAxis.setLabel("Y Axis");
 119         // add starting data
 120         XYChart.Series<String, Number> series = new XYChart.Series<>();
 121         series.setName("Data Series 1");
 122         series.getData().add(new XYChart.Data<String, Number>(CATEGORIES[0], 50d));
 123         series.getData().add(new XYChart.Data<String, Number>(CATEGORIES[1], 80d));
 124         series.getData().add(new XYChart.Data<String, Number>(CATEGORIES[2], 90d));
 125         series.getData().add(new XYChart.Data<String, Number>(CATEGORIES[3], 30d));
 126         series.getData().add(new XYChart.Data<String, Number>(CATEGORIES[4], 122d));
 127         series.getData().add(new XYChart.Data<String, Number>(CATEGORIES[5], 10d));
 128         chart.getData().add(series);
 129         return chart;
 130     }
 131 
 132     @Override public void start(Stage primaryStage) throws Exception {
 133         primaryStage.setScene(new Scene(createContent()));
 134         primaryStage.show();
 135     }
 136 
 137     /**
 138      * Java main for when running without JavaFX launcher
 139      * @param args command line arguments
 140      */
 141     public static void main(String[] args) {
 142         launch(args);
 143     }    
 144 }