5 Replies Latest reply: May 5, 2012 10:26 PM by 913541 RSS

    Horizontal Stacked Bar Chart

    913541
      Hi, forum.

      I would like to make "horizontal" stacked bar chart.
      But following chart looks decidedly wrong.
      Is there any way to create it?
      String austria = "Austria";
      String brazil = "Brazil";
      String france = "France";
      String italy = "Italy";
      String usa = "USA";
      NumberAxis xAxis = new NumberAxis();
      CategoryAxis yAxis = new CategoryAxis();
      StackedBarChart<Number,String> bc = new StackedBarChart<>(xAxis,yAxis);
      bc.setTitle("Country Summary");
      xAxis.setLabel("Value");  
      xAxis.setTickLabelRotation(90);
      yAxis.setLabel("Country");  
      yAxis.setCategories(FXCollections.observableArrayList(austria, brazil, france, italy, usa));
       
      XYChart.Series series1 = new XYChart.Series();
      series1.setName("2003");       
      series1.getData().add(new XYChart.Data(25601.34, austria));
      series1.getData().add(new XYChart.Data(20148.82, brazil));
      series1.getData().add(new XYChart.Data(10000, france));
      series1.getData().add(new XYChart.Data(35407.15, italy));
      series1.getData().add(new XYChart.Data(12000, usa));      
              
      XYChart.Series series2 = new XYChart.Series();
      series2.setName("2004");
      series2.getData().add(new XYChart.Data(57401.85, austria));
      series2.getData().add(new XYChart.Data(41941.19, brazil));
      series2.getData().add(new XYChart.Data(45263.37, france));
      series2.getData().add(new XYChart.Data(117320.16, italy));
      series2.getData().add(new XYChart.Data(14845.27, usa));  
              
      bc.getData().addAll(series1, series2);
      primaryStage.setScene(new Scene(bc, 300, 400));
      primaryStage.show();
      This code is based on JavaFX horizontal bar chart sample code.
      http://docs.oracle.com/javafx/2/charts/bar-chart.htm#CIHJFHDE

      I can create vertical (standard) Stacked Bar Chart.

      Mac OSX
      Java7 u4
      JavaFX 2.1

      Thanks in advance.