0

I use vue-chart.js to draw a simple chart.

import { Line } from 'vue-chartjs';

export default {
 extends: Line,
 mounted() {
   this.renderChart({
   labels: [this.getChartLabels],
   datasets: [
     {
       label: 'Active users',
       backgroundColor: '#f87979',
       data: [this.getChartData],
     },
   ],
 },
 { responsive: true,
   maintainAspectRatio: false,
 });
},
 computed: {
  ...mapGetters(['getFullReport', 'getChartLabels', 'getChartData']),
 },
 methods: {
  ...mapActions(['loadFullReport']),
 },
};

When I console my getter in mounted, I can see that I receive an array with two items but when I reload the page, the array appears to be empty. The chart itself doesn't show any information neither before page reloading nor after. Please help!

1 Answer 1

1

You should add a watcher which watches changes in your getters. And then update the chart over this.$data._chart.update()

Chart.js is not reactive. If your data changes or "comes to late" after your chart instance get rendered, you will see nothing.

I guess you fill your store over an API ? Then it is even more crutial, as your API calls are async.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.