title: JavaFX Duplicate Series Added
body: <p>I am currently learning JavaFX and am trying to create an app that shows a line chart and allows the user to change certain variables which then changes the plotted line.  The way I do this is by removing the series (and the data points within the series) and then refilling the series and adding them again as shown below.</p>
  
  <pre><code>    public void plot(double[] xArr, double[] yExactArr, double[] yApproxArr) {
          linePlot.getData().clear();
  
          if (!exactValues.getData().isEmpty()) {
              exactValues.getData().remove(0, xArr.length - 1);
              approxValues.getData().remove(0, xArr.length - 1);
          }
  
          for (int i = 0; i &lt; xArr.length; i++) {
              exactValues.getData().add(new XYChart.Data(xArr[i], yExactArr[i]));
              approxValues.getData().add(new XYChart.Data(xArr[i], yApproxArr[i]));
          }
  
  
          linePlot.getData().addAll(exactValues, approxValues);
          mainStage.show();
      }
  </code></pre>
  
  <p>However, when I do this I am getting the following error:</p>
  
  <pre><code>    Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Duplicate series added
  </code></pre>
  
  <p>This occurs as soon as <code>addAll()</code> is called the second time around.  When I print the <code>toString()</code> function of <code>linePlot.getData()</code> after calling <code>clear()</code>, it prints an empty array, so it seems like there shouldn't be a problem.  My guess is this isn't the proper way of going about changing the line but this is my newbie attempt.  It seems like I should be able to just change the data within the series (without removing and readding them) but then my plot doesn't update.</p>
  
  <p>Any ideas/recommendations?</p>