title: Clear only the visible data data from Chart
body: <p>I have this example of javaFX LineChart. I would like to reset the data into the chart.</p>
  
  <pre><code>public class MainApp extends Application
  {
      private static final int MAX_DATA_POINTS = 50;
  
      private Series series;
      private int xSeriesData = 0;
      private final ConcurrentLinkedQueue&lt;Number&gt; dataQ = new ConcurrentLinkedQueue&lt;&gt;();
      private ExecutorService executor;
      private AddToQueue addToQueue;
      private Timeline timeline2;
      private NumberAxis xAxis;
      private NumberAxis yAxis;
      private AreaChart&lt;Number, Number&gt; sc;
  
      private void init(Stage primaryStage)
      {    
          xAxis = new NumberAxis(0, MAX_DATA_POINTS, MAX_DATA_POINTS / 10);
          xAxis.setForceZeroInRange(false);
          xAxis.setAutoRanging(false);
  
          yAxis = new NumberAxis();
          yAxis.setAutoRanging(true);
  
          sc = new AreaChart&lt;Number, Number&gt;(xAxis, yAxis);
  
          sc.setAnimated(false);
          sc.setId("liveAreaChart");
          series = new AreaChart.Series&lt;Number, Number&gt;();
          series.setName("Area Chart Series");
          sc.getData().add(series);
          primaryStage.setScene(new Scene(sc));
      }
  
      @Override
      public void start(Stage primaryStage) throws Exception
      {
          init(primaryStage);
          primaryStage.show();
  
          executor = Executors.newCachedThreadPool(new ThreadFactory()
          {
              @Override
              public Thread newThread(Runnable r)
              {
                  Thread thread = new Thread(r);
                  thread.setDaemon(true);
                  return thread;
              }
          });
          addToQueue = new AddToQueue();
          executor.execute(addToQueue);
          prepareTimeline();
      }
  
      public static void main(String[] args)
      {
          launch(args);
      }
  
      private class AddToQueue implements Runnable
      {
          @Override
          public void run()
          {
              try
              {
                  dataQ.add(Math.random());
                  Thread.sleep(50);
                  executor.execute(this);
              }
              catch (InterruptedException ex)
              {
                  Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      }
  
      private void prepareTimeline()
      {
          new AnimationTimer()
          {
              @Override
              public void handle(long now)
              {
                  addDataToSeries();
              }
          }.start();
      }
  
      private void addDataToSeries()
      {
          for (int i = 0; i &lt; 20; i++)
          { //-- add 20 numbers to the plot+
              if (dataQ.isEmpty())
                  break;
              series.getData().add(new AreaChart.Data(xSeriesData++, dataQ.remove()));
          }
  
          if (series.getData().size() &gt; MAX_DATA_POINTS)
          {
              series.getData().remove(0, series.getData().size() - MAX_DATA_POINTS);
          }
          xAxis.setLowerBound(xSeriesData - MAX_DATA_POINTS);
          xAxis.setUpperBound(xSeriesData - 1);
      }
  }
  </code></pre>
  
  <p>What is the proper way to implement this?</p>
  
  <p>I suppose that I have to clear the chart's buffer but I can't find proper solution.</p>
  
  <p>I tested to use <code>sc.getData().clear();</code> but this code clears all data. I would like to clear only the visible data. </p>