Update Chart with computed property, how does reactiveData work?
See original GitHub issueI’d like to update the chart data but I need to transform the data so I’m using a computed property. With that I can’t use the reactiveProp
as mentioned in the docs: https://vue-chartjs.org/guide/#updating-charts right? But how to use reactiveData
?
I’m now using this:
import { HorizontalBar } from "vue-chartjs";
export default {
extends: HorizontalBar,
props: ["chartdata"],
watch: {
chartdata: function() {
this.$data._chart.data.datasets = this.datasets;
this.$data._chart.update();
}
},
computed: {
datasets: function() {
let datasets = [];
for (let key in this.chartdata) {
datasets.push({
data: [this.chartdata[key]],
backgroundColor: "#123456"
});
}
return datasets;
}
},
mounted() {
this.renderChart(
{
datasets: this.datasets
},
{
...
}
);
}
};
Can this be done easier or cleaner?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Computed Properties - Vue.js
A computed property will only re-evaluate when some of its reactive dependencies have changed. This means as long as author.
Read more >Vue Chart.js - Chart is not updating when data is changing
Use a computed property for the chart data. ... But, this don't work until I change the chartData in another component like this:...
Read more >Examining Update Events with Computed Properties in Vue.js
Because computed properties are typically calculated using instance data, their return value is updated automatically when the underlying data ...
Read more >Exploring VueJS: Data binding with Computed Properties and ...
Computed property allows us to cache and update specific data whose value depends on other reactive data property, in a more declarative manner....
Read more >When To Use Computed In Vue.js?(How It Works, Examples)
Table Of Contents. 1 How Do Computed Properties Work In Vue.js? ... This button is going to be able to change the name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s a while back, just looked up the code and it’s the same.
@royduin Hi Roy, Did you solve this? Would you be willing to share some code if you found a solution? I am having the exact same ‘challenge’: vuefire data in copmputed properties. The v-if=“loaded” i couldn’t get to work. Leuke website heb je!