How can I update the data from the series for an ApexCharts I have created the following Vue Component using the ApexCharts. This component gets updated from the parent where a bunch of these components are situated. The updated values are coming in through props.
<template>
<div>
<apexchart type="line" width="1000px" :options="options" :series="series"></apexchart>
</div>
</template>
<script>
import Vue from 'vue';
import VueApexCharts from 'vue-apexcharts';
Vue.use(VueApexCharts);
Vue.component('apexchart', VueApexCharts);
export default {
name: 'EnergyConsumption',
props: {
channel1: Number,
channel2: Number,
},
data() {
return {
options: {
chart: {
id: 'vuechart-example',
},
xaxis: {
categories: ['Channel 1', 'Channel 2'],
},
},
series: [
{
name: 'series-1',
data: [this.channel1, this.channel2],
},
],
};
},
methods: {
updateSeries() {
this.series[0].data = [this.channel1, this.channel2];
},
},
watch: {
channel1: function (_channel1) {
this.updateSeries();
// this.series[0].data[0] = _channel1;
},
},
};
</script>
With the Vue DevTools I can see that the data is changing inside the ApexCharts component, but the view is not updated.
If I take a look in the ApexCharts documentation, I see there is a method to update the series
updateSeries (newSeries, animate)
But I need an instance to call the updateSeries
from. If I use the template mechanism, I can't have a reference to that module.
What is the best way to solve this issue?