diff --git a/src/plugins/plot/configuration/PlotSeries.js b/src/plugins/plot/configuration/PlotSeries.js index dfe8e3d11a..fd40cfa89d 100644 --- a/src/plugins/plot/configuration/PlotSeries.js +++ b/src/plugins/plot/configuration/PlotSeries.js @@ -507,8 +507,12 @@ export default class PlotSeries extends Model { const pointsToRemove = startIndex + (data.length - endIndex + 1); if (pointsToRemove > 0) { if (pointsToRemove < 1000) { + // Remove all points up to the start index data.slice(0, startIndex).forEach(this.remove, this); - data.slice(endIndex, data.length).forEach(this.remove, this); + // Re-calculate the endIndex since the data array has changed, + // then remove items from endIndex to the end of the array + const newEndIndex = endIndex - startIndex + 1; + data.slice(newEndIndex, data.length).forEach(this.remove, this); this.updateSeriesData(data); this.resetStats(); } else {