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.stacked; 33 34 35 import javafx.application.Application; 36 import static javafx.collections.FXCollections.*; 37 import javafx.collections.ObservableList; 38 import javafx.scene.Parent; 39 import javafx.scene.Scene; 40 import javafx.scene.chart.CategoryAxis; 41 import javafx.scene.chart.NumberAxis; 42 import javafx.scene.chart.StackedBarChart; 43 import javafx.stage.Stage; 44 45 46 /** 47 * A sample that displays data in a stacked bar chart. 48 * 49 * @sampleName Stacked Bar Chart 50 * @preview preview.png 51 * @see javafx.scene.chart.StackedBarChart 52 * @see javafx.scene.chart.CategoryAxis 53 * @see javafx.scene.chart.NumberAxis 54 * @related /Charts/Bar/Bar Chart 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=-3000,max=0,step=1) 73 * @playground yAxis.upperBound (min=0,max=8000,step=1) 74 * @playground yAxis.tickUnit (max=5000,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 StackedBarChartApp extends Application { 99 100 private StackedBarChart chart; 101 private CategoryAxis xAxis; 102 private NumberAxis yAxis; 103 104 public Parent createContent() { 105 String[] years = {"2007", "2008", "2009"}; 106 xAxis = new CategoryAxis(observableArrayList(years)); 107 yAxis = new NumberAxis("Units Sold", 0.0d, 10000.0d, 1000.0d); 108 109 ObservableList<StackedBarChart.Series> barChartData = 110 observableArrayList( 111 new StackedBarChart.Series("Region 1", 112 observableArrayList( 113 new StackedBarChart.Data(years[0], 567d), 114 new StackedBarChart.Data(years[1], 1292d), 115 new StackedBarChart.Data(years[2], 1292d) 116 ) 117 ), 118 new StackedBarChart.Series("Region 2", 119 observableArrayList( 120 new StackedBarChart.Data(years[0], 956), 121 new StackedBarChart.Data(years[1], 1665), 122 new StackedBarChart.Data(years[2], 2559) 123 ) 124 ), 125 new StackedBarChart.Series("Region 3", 126 observableArrayList( 127 new StackedBarChart.Data(years[0], 1154), 128 new StackedBarChart.Data(years[1], 1927), 129 new StackedBarChart.Data(years[2], 2774) 130 ) 131 ) 132 ); 133 134 chart = new StackedBarChart(xAxis, yAxis, barChartData, 25.0d); 135 return chart; 136 } 137 138 139 @Override public void start(Stage primaryStage) throws Exception { 140 primaryStage.setScene(new Scene(createContent())); 141 primaryStage.show(); 142 } 143 144 /** 145 * Java main for when running without JavaFX launcher 146 * @param args command line arguments 147 */ 148 public static void main(String[] args) { 149 launch(args); 150 } 151 }