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