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  * @playground - (name="xAxis")
  57  * @playground xAxis.autoRanging
  58  * @playground xAxis.gapStartAndEnd
  59  * @playground xAxis.startMargin
  60  * @playground xAxis.endMargin
  61  * @playground xAxis.animated
  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,max=0,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.side
  80  * @playground yAxis.tickLabelFill
  81  * @playground yAxis.tickLabelGap
  82  * @playground yAxis.tickLabelRotation (min=-180,max=180,step=1)
  83  * @playground yAxis.tickLabelsVisible
  84  * @playground yAxis.tickLength
  85  * @playground yAxis.tickMarkVisible
  86  * @playground - (name="chart")
  87  * @playground chart.horizontalGridLinesVisible
  88  * @playground chart.horizontalZeroLineVisible
  89  * @playground chart.verticalGridLinesVisible
  90  * @playground chart.verticalZeroLineVisible
  91  * @playground chart.animated
  92  * @playground chart.legendSide
  93  * @playground chart.legendVisible
  94  * @playground chart.title
  95  * @playground chart.titleSide
  96  */
  97 public class ImageBarChartApp extends Application {
  98     
  99     private BarChart chart;
 100     private CategoryAxis xAxis;
 101     private NumberAxis yAxis;
 102 
 103     public Parent createContent() {
 104         xAxis = new CategoryAxis();
 105         yAxis = new NumberAxis();
 106         chart = new BarChart(xAxis, yAxis);
 107         chart.setLegendVisible(false);
 108         chart.getStylesheets().add(ImageBarChartApp.class
 109                 .getResource("ImageBarChart.css").toExternalForm());
 110 
 111         chart.getData().add(
 112                 new XYChart.Series<>("Sales Per Product",
 113                     FXCollections.observableArrayList(
 114                         new XYChart.Data<>("SUV", 120),
 115                         new XYChart.Data<>("Sedan", 50),
 116                         new XYChart.Data<>("Truck", 180),
 117                         new XYChart.Data<>("Van", 20)
 118                     )
 119                 )
 120         );
 121         return chart;
 122     }
 123     
 124     
 125     @Override public void start(Stage primaryStage) throws Exception {
 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 }