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.bar.image;
  33 
  34 
  35 import javafx.application.Application;
  36 import javafx.collections.FXCollections;
  37 import javafx.scene.Parent;
  38 import javafx.scene.Scene;
  39 import javafx.scene.chart.BarChart;
  40 import javafx.scene.chart.CategoryAxis;
  41 import javafx.scene.chart.NumberAxis;
  42 import javafx.scene.chart.XYChart;
  43 import javafx.stage.Stage;
  44 
  45 
  46 /**
  47  * A bar chart that uses CSS to display stacks of car images to indicate data values
  48  * for categories. 
  49  *
  50  * @sampleName Image Bar Chart
  51  * @preview preview.png
  52  * @see javafx.scene.chart.BarChart
  53  * @see javafx.scene.chart.CategoryAxis
  54  * @see javafx.scene.chart.NumberAxis
  55  * @playground chart.data
  56  * 
  57  * @playground - (name="xAxis")
  58  * @playground xAxis.autoRanging
  59  * @playground xAxis.gapStartAndEnd
  60  * @playground xAxis.startMargin
  61  * @playground xAxis.endMargin
  62  * 
  63  * @playground xAxis.animated
  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,max=0,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.side
  84  * @playground yAxis.tickLabelFill
  85  * @playground yAxis.tickLabelGap
  86  * @playground yAxis.tickLabelRotation (min=-180,max=180,step=1)
  87  * @playground yAxis.tickLabelsVisible
  88  * @playground yAxis.tickLength
  89  * @playground yAxis.tickMarkVisible
  90  * 
  91  * @playground - (name="chart")
  92  * @playground chart.horizontalGridLinesVisible
  93  * @playground chart.horizontalZeroLineVisible
  94  * @playground chart.verticalGridLinesVisible
  95  * @playground chart.verticalZeroLineVisible
  96  * 
  97  * @playground chart.animated
  98  * @playground chart.legendSide
  99  * @playground chart.legendVisible
 100  * @playground chart.title
 101  * @playground chart.titleSide
 102  */
 103 public class ImageBarChartApp extends Application {
 104     
 105     private BarChart chart;
 106     private CategoryAxis xAxis;
 107     private NumberAxis yAxis;
 108 
 109     public Parent createContent() {
 110         xAxis = new CategoryAxis();
 111         yAxis = new NumberAxis();
 112         chart = new BarChart(xAxis, yAxis);
 113         chart.setLegendVisible(false);
 114         chart.getStylesheets().add(ImageBarChartApp.class
 115                 .getResource("ImageBarChart.css").toExternalForm());
 116 
 117         chart.getData().add(
 118                 new XYChart.Series<>("Sales Per Product",
 119                     FXCollections.observableArrayList(
 120                         new XYChart.Data<>("SUV", 120),
 121                         new XYChart.Data<>("Sedan", 50),
 122                         new XYChart.Data<>("Truck", 180),
 123                         new XYChart.Data<>("Van", 20)
 124                     )
 125                 )
 126         );
 127         return chart;
 128     }
 129     
 130     
 131     @Override public void start(Stage primaryStage) throws Exception {
 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 }