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

LineChart plots obsolete series data

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 7u21
    • javafx
    • Windows 7 64-bit

    Description

      This issue might be related to issue RT-30876. I add two series to a line chart. I then remove one of the series and change the y-data values. When I add the series back to the chart, the chart does not display the changed data values; it displays the data as it was when it was removed from the chart.

      Below is a small application that demonstrates the problem. When the series is added back to the plot, I print the changed values to the console so you can see the values are changed but that change is not reflected on the plot.

      This problem also occurs in Java 8 / JavaFX 8 (specifically 8.0.0-ea-b92 [30 May 2013]).

      package com.scenaria.sandbox;

      import javafx.application.Application;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.chart.LineChart;
      import javafx.scene.chart.NumberAxis;
      import javafx.scene.chart.XYChart;
      import javafx.scene.chart.XYChart.Series;
      import javafx.scene.control.Button;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class ChangeDataTest extends Application {
          
          @Override
          public void start(Stage stage) {
              stage.setTitle("Line Chart Sample");
              
              final NumberAxis xAxis = new NumberAxis();
              final NumberAxis yAxis = new NumberAxis();
              xAxis.setLabel("Month Number");
              
              final LineChart<Number,Number> lineChart =
                      new LineChart<Number,Number>(xAxis,yAxis);
              lineChart.setTitle("Stock Monitoring, 2010");
              
              XYChart.Series series1 = new XYChart.Series();
              series1.setName("Series 1");
              series1.getData().add(new XYChart.Data(1, 23));
              series1.getData().add(new XYChart.Data(3, 15));
              series1.getData().add(new XYChart.Data(5, 34));
              series1.getData().add(new XYChart.Data(7, 22));
              series1.getData().add(new XYChart.Data(9, 43));
              series1.getData().add(new XYChart.Data(11, 29));
              
              final XYChart.Series series2 = new XYChart.Series();
              series2.setName("Series 2");
              series2.getData().add(new XYChart.Data(1, 10));
              series2.getData().add(new XYChart.Data(3, 11));
              series2.getData().add(new XYChart.Data(5, 28));
              series2.getData().add(new XYChart.Data(7, 18));
              series2.getData().add(new XYChart.Data(9, 35));
              series2.getData().add(new XYChart.Data(11, 22));
              
              BorderPane bdrPane = new BorderPane();
              bdrPane.setCenter(lineChart);
              
              Button rmSeries2Btn = new Button();
              rmSeries2Btn.setText("Remove Series 2");
              rmSeries2Btn.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent t) {
                      ObservableList<Series<Number, Number>> data = lineChart.getData();
                      Series<Number, Number> removedSeries = data.remove(1);
                  }
              });
              
              Button changeSeriesBtn = new Button();
              changeSeriesBtn.setText("Change Series");
              changeSeriesBtn.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent t) {
                      ObservableList<XYChart.Data<Number, Number>> data = series2.getData();
                      for (XYChart.Data<Number, Number> dataPoint : data) {
                          double newValue = dataPoint.getYValue().doubleValue() * 1.25;
                          dataPoint.setYValue(newValue);
                      }
                  }
              });
              
              Button addSeriesBackBtn = new Button();
              addSeriesBackBtn.setText("Add Series Back");
              addSeriesBackBtn.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent t) {
                      System.out.println("Series 2 Data:");
                      ObservableList<XYChart.Data<Number, Number>> data = series2.getData();
                      for (XYChart.Data<Number, Number> dataPoint : data) {
                          double xValue = dataPoint.getXValue().doubleValue();
                          double yValue = dataPoint.getYValue().doubleValue();
                          System.out.println(" (" + xValue + ", " + yValue +")");
                      }
                      
                      lineChart.getData().add(series2);
                  }
              });
              
              HBox buttonHBox = new HBox();
              buttonHBox.getChildren().addAll(rmSeries2Btn, changeSeriesBtn, addSeriesBackBtn);
              bdrPane.setBottom(buttonHBox);
              
              Scene scene = new Scene(bdrPane,800,600);
              
              lineChart.getData().add(series1);
              lineChart.getData().add(series2);
             
              stage.setScene(scene);
              stage.show();
              
              System.out.println("JavaFX version: " + System.getProperties().get("javafx.runtime.version"));
              System.out.println("Java version: " + System.getProperties().get("java.version"));
          }
       
          public static void main(String[] args) {
              launch(args);
          }
          
      }

      Attachments

        Activity

          People

            psomashe Parvathi Somashekar (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: