Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8126380

[BarChart] only the last data from serie of added to a category, is actually added to the category.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 8
    • 7u6
    • javafx
    • 2.2.0b15

      Run the code to reproduce the issue.

      You may see, observing the code, that I try to add 10 data items, distributed between 3 categories. Each category receives more than 1 data item. But each category adds only 1 (the last) data item.

      Code:


      import java.util.Random;
      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.chart.BarChart;
      import javafx.scene.chart.CategoryAxis;
      import javafx.scene.chart.NumberAxis;
      import javafx.scene.chart.XYChart;
      import javafx.scene.control.Button;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class JavaCharts extends Application {

          public static void main(String[] args) {
              launch(args);
          }
          NumberAxis axisY = new NumberAxis(0, 100, 10);
          ObservableList<String> existingCategories = FXCollections.observableArrayList();
          CategoryAxis axisX = new CategoryAxis(existingCategories);
          BarChart testedBarChart = new BarChart(axisY, axisX);
          VBox vb = new VBox();

          @Override
          public void start(Stage stage) throws Exception {
              testedBarChart.setTitle("BarChart");
              testedBarChart.setStyle("-fx-border-color: darkgray;");
              existingCategories.addAll("category1", "category2", "category3");

              addDataToChart(3);

              Pane pane = new Pane();
              pane.setPrefSize(600, 600);

              pane.setPrefSize(600, 600);
              pane.getChildren().add(testedBarChart);

              Button buttonAddMany = new Button("Add data to three categories - click me many times");
              buttonAddMany.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent t) {
                      addDataToChart(10);
                  }
              });

              vb.getChildren().addAll(pane, buttonAddMany);

              Scene scene = new Scene(vb, 700, 700);
              stage.setScene(scene);
              stage.show();
          }

          private void addDataToChart(int amount) {
              double min = 0;
              double max = 100;

              ObservableList list = FXCollections.observableArrayList();

              XYChart.Series serie = new XYChart.Series("SeriesName", list);

              for (int i = 0; i < amount; i++) {
                  XYChart.Data newData = new XYChart.Data();
                  String category = existingCategories.get(i % existingCategories.size());
                  Double value = new Random().nextDouble() * (max - min) + min;
                  newData.setYValue(category);
                  newData.setXValue(value);
                  list.add(newData);
                  System.out.println(newData + " to category " + category + " value " + value);
              }

              testedBarChart.getData().add(serie);
          }
      }

      Steps: click button many times.

            psomashe Parvathi Somashekar (Inactive)
            akirov Alexander Kirov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: