removeTimeSeries is broken because it is trying to find the index of the TimeSeries to remove by using indexOf, but the array object is not pointing to the TimeSeries directly so it always returns -1, which deletes the last element on the array.
The array seriesSet stores objects that do point to a TimeSeries, so the correct code should be something like this:
SmoothieChart.prototype.removeTimeSeries = function(timeSeries) {
var numSeries = this.seriesSet.length;
for (var i = 0; i < numSeries; i++)
{
if (this.seriesSet[i].timeSeries === timeSeries)
{
this.seriesSet.splice(i, 1);
break;
}
}
};
removeTimeSeries
is broken because it is trying to find the index of the TimeSeries to remove by usingindexOf
, but the array object is not pointing to the TimeSeries directly so it always returns -1, which deletes the last element on the array.The array
seriesSet
stores objects that do point to a TimeSeries, so the correct code should be something like this: