I want to use highcharts to display an initial set of data and then every two seconds add a new data point. I am subscribing to an external WebSocket services that initially provides me with the data and then sends me a new value every two seconds.
I am using the events option in Highcharts to try and get the data out of the vuex store. Here is my code.
chart:{
type: 'spline',
animation: '',
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
series.addPoint([this.$store.getters.getTickEpoch, this.$store.getters.getTickQuote], true, true);
}.bind(this), 1000);
}.bind(this)
}
}
The problem is that if I don't add .bind(this) to my functions, I can't see the vuex store, but when I do add .bind(this) then var series = this.series[0]; no longer works.
How do I use vuex data to update my chart in real time?
Highcharts.chartsis an array of all charts on the page. If you only have one chart on the page then the series you need isHighcharts.charts[0].series[0].chartvariable is still not defined when theloadevent fires but the chart is already saved inHighcharts.chartsarray.