Chart do not update
asakurayoh opened this issue · 6 comments
When I change the datasets send to Chartjs.vue, the Chart do not refresh.
It run the this.chart.update() line but that do nothing.
Thanks.
Need more details. Thanks.
I'm having this problem when I'm using vuex to store the data and try to get by this way:
computed: {
labels () {
return this.$store.state.data.locations.map(it => it.city)
},
data () {
return this.$store.state.data.locations.map(it => it.qty)
},
chartData () {
return {
labels: this.labels,
datasets: [{
data: this.data,
backgroundColor: [
'#F44336',
'#3F51B5',
'#4CAF50',
'#FF9800',
'#9E9E9E',
'#795548',
'#607D8B',
'#01579B'
]
}]
}
After mounted, the chart does not change when the store changes.
@danilo-drs
Well chart.js does not recognize changes itself. So if data changes, you have to add a watcher or event and update the chart instance yourself.
But it's important to notice, that chart.update()
only works if data is changed. If you add a new dataset you have to create a new instance.
@asakurayoh but how can I call the method without any "chart" instance?
this issue is fixed. Now you can simply bind the data/options to chartjs from parent component.
Thanks!
I'm still experiencing this issue.