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. T
Only add your series once to the chart initially when creating your chart.
Update the data without adding the series again:
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 < 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();
}