1 /*
   2      * @param args command line arguments
   3  * Copyright (c) 2008, 2014, Oracle and/or its affiliates.
   4  * All rights reserved. Use is subject to license terms.
   5  *
   6  * This file is available and licensed under the following license:
   7  *
   8  * Redistribution and use in source and binary forms, with or without
   9  * modification, are permitted provided that the following conditions
  10  * are met:
  11  *
  12  *  - Redistributions of source code must retain the above copyright
  13  *    notice, this list of conditions and the following disclaimer.
  14  *  - Redistributions in binary form must reproduce the above copyright
  15  *    notice, this list of conditions and the following disclaimer in
  16  *    the documentation and/or other materials provided with the distribution.
  17  *  - Neither the name of Oracle Corporation nor the names of its
  18  *    contributors may be used to endorse or promote products derived
  19  *    from this software without specific prior written permission.
  20  *
  21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  */
  33 
  34 package ensemble.samples.charts.bar.chart;
  35 
  36 
  37 import javafx.application.Application;
  38 import javafx.collections.FXCollections;
  39 import javafx.collections.ObservableList;
  40 import javafx.scene.Parent;
  41 import javafx.scene.Scene;
  42 import javafx.scene.chart.BarChart;
  43 import javafx.scene.chart.CategoryAxis;
  44 import javafx.scene.chart.NumberAxis;
  45 import javafx.stage.Stage;
  46 
  47 
  48 /**
  49  * A chart that displays rectangular bars with heights indicating data values
  50  * for categories. Used for displaying information when at least one axis has
  51  * discontinuous or discrete data.
  52  *
  53  * @sampleName Bar Chart
  54  * @preview preview.png
  55  * @see javafx.scene.chart.BarChart
  56  * @see javafx.scene.chart.CategoryAxis
  57  * @see javafx.scene.chart.NumberAxis
  58  * @related /Charts/Area/Area Chart
  59  * @related /Charts/Line/Line Chart
  60  * @related /Charts/Scatter/Scatter Chart
  61  * @docUrl https://docs.oracle.com/javafx/2/charts/jfxpub-charts.htm Using JavaFX Charts Tutorial
  62  * @playground chart.data
  63  * @playground - (name="xAxis")
  64  * @playground xAxis.autoRanging
  65  * @playground xAxis.gapStartAndEnd
  66  * @playground xAxis.startMargin
  67  * @playground xAxis.endMargin
  68  * @playground xAxis.animated
  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=-1000,max=3000,step=1)
  80  * @playground yAxis.upperBound (max=4000,step=1)
  81  * @playground yAxis.tickUnit (max=3000,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,step=1)
  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 BarChartApp extends Application {
 107     
 108     private BarChart chart;
 109     private CategoryAxis xAxis;
 110     private NumberAxis yAxis;
 111 
 112     public Parent createContent() {
 113         String[] years = {"2007", "2008", "2009"};
 114         xAxis = new CategoryAxis();
 115         xAxis.setCategories(FXCollections.<String>observableArrayList(years));
 116         yAxis = new NumberAxis("Units Sold", 0.0d, 3000.0d, 1000.0d);
 117         ObservableList<BarChart.Series> barChartData = FXCollections.observableArrayList(
 118             new BarChart.Series("Apples", FXCollections.observableArrayList(
 119                new BarChart.Data(years[0], 567d),
 120                new BarChart.Data(years[1], 1292d),
 121                new BarChart.Data(years[2], 1292d)
 122             )),
 123             new BarChart.Series("Lemons", FXCollections.observableArrayList(
 124                new BarChart.Data(years[0], 956),
 125                new BarChart.Data(years[1], 1665),
 126                new BarChart.Data(years[2], 2559)
 127             )),
 128             new BarChart.Series("Oranges", FXCollections.observableArrayList(
 129                new BarChart.Data(years[0], 1154),
 130                new BarChart.Data(years[1], 1927),
 131                new BarChart.Data(years[2], 2774)
 132             ))
 133         );
 134         chart = new BarChart(xAxis, yAxis, barChartData, 25.0d);
 135         return chart;
 136     }
 137 
 138     @Override public void start(Stage primaryStage) throws Exception {
 139         primaryStage.setScene(new Scene(createContent()));
 140         primaryStage.show();
 141     }
 142 
 143     /**
 144      * Java main for when running without JavaFX launcher
 145      * @param args command line arguments
 146      */
 147     public static void main(String[] args) {
 148         launch(args);
 149     }
 150 }