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

Line not removed from LineChart when series cleared

XMLWordPrintable

    • b08
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Linux, Redhat 8, repeated with JavaFX 16, 11.0.2 and 18

      A DESCRIPTION OF THE PROBLEM :
      When the series is cleared the points (aka symbols?) are removed from the line chart but the line remains.
      This is a regression. This functionality worked as expected in Java 1.8.0_311

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the example
      Press Add button
      Press Remove button

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Line and points to be removed from line chart
      ACTUAL -
      Points removed but line remains

      ---------- BEGIN SOURCE ----------
      import java.util.ArrayList;
      import java.util.List;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.chart.LineChart;
      import javafx.scene.chart.NumberAxis;
      import javafx.scene.chart.XYChart.Data;
      import javafx.scene.chart.XYChart.Series;
      import javafx.scene.control.Button;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class LineChartClearIssue extends Application {
      @Override
      public void start(Stage stage) throws Exception {

      LineChart<Number, Number> lineChart = new LineChart<>(new NumberAxis(), new NumberAxis());
      lineChart.setAnimated(false);
      Series<Number, Number> series = new Series<>();
      series.setName("Dave");
      lineChart.getData().add(series);

      Button add = new Button("Add");
      Button remove = new Button("Remove");
      Button workaround = new Button("Workaround");
      add.setOnAction(event -> {
      series.getData().add(new Data<>(1, 10));
      series.getData().add(new Data<>(2, 20));
      });
      remove.setOnAction(event -> series.getData().clear());
      workaround.setOnAction(event -> {
      // copy data and add again
      List<Series<Number, Number>> rigby = new ArrayList<>(lineChart.getData());
      lineChart.getData().setAll(rigby);
      });

      stage.setScene(new Scene(new VBox(add, remove, workaround, lineChart)));
      stage.show();
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Remove all the series and then add again, i.e.

      List<Series<Number, Number>> copy = new ArrayList<>(lineChart.getData());
      lineChart.getData().setAll(copy);

      FREQUENCY : always


            kpk Karthik P K
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: