question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update Chart with computed property, how does reactiveData work?

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
royduincommented, Nov 5, 2019

It’s a while back, just looked up the code and it’s the same.

0reactions
dizidcommented, Nov 4, 2019

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found