I use Vue.js and Chart.js to draw a chart. Each time I call the generateChart() function, the chart does not update automatically. When I check the data in VueDevTools , they are correct, but the diagram does not represent them.
Interesting fact: the chart is updated when I resize the window.
- What is wrong with what I'm doing?
- How to update a chart every time I call
generateChart() ?
I feel this will be due to object and array changing the detour bypass, but I'm not sure what to do.
https://codepen.io/anon/pen/bWRVKB?editors=1010
<el-dialog title="Chart" v-model="showGeneratedChart"> <line-chart :chartData="dataChart"></line-chart> </el-dialog> export default{ data (){ const self = this; return { dataChart : { labels : [], datasets: [{ label: 'label', backgroundColor: '#FC2525', data: [0, 1, 2, 3, 4], }] } } } generateChart() { this.dataChart['labels'] = []; this.dataChart['datasets'] = []; ... compute datasets and formattedLabels this.dataChart['labels'] = formattedLabels; this.dataChart['datasets'] = datasets; }
LineChart.js
import { Line, mixins } from 'vue-chartjs' export default Line.extend({ mixins: [mixins.reactiveProp], props: ["options"], mounted () { this.renderChart(this.chartData, this.options) } })
source share