Chartjs-Chart.js chart in vue.js component does not update

1👍

The problem you have here is how vuejs handles its data.

If you use it like that:

local_data.forEach(element => {
    this.portfolio_value.push(element.total_usd);
    this.portfolio_labels.push(moment(element.timestamp, 'X'));
});

this.chart.update();

The chart will update. But by re-initializing the arrays you work against vuejs.

TL;DR

If you want to re-initialize an object, you could assign the array to the object:

Object.assign(this.portfolio_value, values);
Object.assign(this.portfolio_labels, labels);

That way, the linking stays working.

Leave a comment