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

LineChart clearing the series data throws IndexOutOfBoundsException when animated=true

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 9
    • 8u40
    • javafx
    • None

      Clearing the data of linechart series throws IndexOutOfBoundsException. Please see following example:

      @Override
          public void start( final Stage stage )
          {
              stage.setTitle( "Line Chart Sample" );
              //defining the axes
              final NumberAxis xAxis = new NumberAxis();
              final NumberAxis yAxis = new NumberAxis();
              xAxis.setLabel( "Number of Month" );
              //creating the chart
              final LineChart<Number, Number> lineChart
                      = new LineChart<Number, Number>( xAxis, yAxis );

              lineChart.setTitle( "Stock Monitoring, 2010" );
              //defining a series
              XYChart.Series series = new XYChart.Series();
              series.setName( "My portfolio" );
              //populating the series with data
              series.getData().add( new XYChart.Data( 1, 23 ) );
              series.getData().add( new XYChart.Data( 2, 14 ) );
              series.getData().add( new XYChart.Data( 3, 15 ) );
              series.getData().add( new XYChart.Data( 4, 24 ) );
              series.getData().add( new XYChart.Data( 5, 34 ) );
              series.getData().add( new XYChart.Data( 6, 36 ) );
              series.getData().add( new XYChart.Data( 7, 22 ) );
              series.getData().add( new XYChart.Data( 8, 45 ) );
              series.getData().add( new XYChart.Data( 9, 43 ) );
              series.getData().add( new XYChart.Data( 10, 17 ) );
              series.getData().add( new XYChart.Data( 11, 29 ) );
              series.getData().add( new XYChart.Data( 12, 25 ) );

              Button b = new Button( "clear" );
              b.setOnAction( new EventHandler<ActionEvent>()
              {
                  @Override
                  public void handle( ActionEvent event )
                  {
                      // lineChart.setAnimated( false);
                      lineChart.getData().get( 0 ).getData().clear();
                     // lineChart.setAnimated( true);
                  }
              } );

              Scene scene = new Scene( new VBox( b, lineChart ), 800, 600 );
              lineChart.getData().add( series );

              stage.setScene( scene );
              stage.show();
          }



      Related issue: RT-40632 but it was resolved as "Incomplete".
      Related discussion: http://stackoverflow.com/questions/30395802/xychart-series-getdata-clear-throws-indexoutofboundsexception
      Bug is on line:
      XYChart.Data<X, Y> p2 = series.getItem( itemIndex + 1 );
      of
      LineChart.dataItemRemoved(...) method.

            vadim Vadim Pakhnushev
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: