Reputation: 2186
I am adding points in column chart every 1 sec. I have use addPoint function to adding point in series. But I would like to delete the first point when count of point > 5. Please see the code below:
setInterval(() => {
let data = self.loadData();
let seriesData = this.userOptions.series[0].data;
let newDataRejected = seriesData;
if (seriesData.length > 5) {
self.chart.series[0].data[0].remove();#ERROR
}
data.subscribe(el => {
this.series[0].addPoint([el.x, el.rejected]);
})
}, 1000);
But in LINE #ERROR I get error Cannot read property '0' of undefined
.
How can I add and remove Points in column chats?
Upvotes: 1
Views: 838
Reputation: 5803
Instead of manually removing the first point, a better solution is to use the shift property of the addPoint
function.
You would then need to do:
setInterval(() => {
let data = self.loadData();
let seriesData = this.userOptions.series[0].data;
let newDataRejected = seriesData;
if (seriesData.length > 5) {
data.subscribe(el => {
this.series[0].addPoint([el.x, el.rejected], true, true);
})
} else {
data.subscribe(el => {
this.series[0].addPoint([el.x, el.rejected], true, false);
})
}
}, 1000);
Working example: https://jsfiddle.net/ewolden/1c5hkj8g/
Upvotes: 2