Chartjs-Update chart in Chart js

0👍

I’m not familiar the way of your implement.
But it seems like java, so you need member variable, and access them using this from each function.

let AnalyticsChart = {
    chart: null,
    buildChart() {
        /** omit **/
        this.chart = new Chart(ctx, {
    ~
    update() {
        /** omit **/
        this.chart.update();

I’m sorry I don’t quite understand the question2.
Do you want to push the data, rather than update? If so, you can’t do it just prepare the value. (I mean, you need labels, background…)
If you just want to update the chart, that is a piece of cake

this.chart.data.datasets.forEach((dataset) => {
    dataset.data = counts;
});

Remember, you have one datasets.
If datasets is not dynamically, I think there’s no need to loop.

this.chart.data.datasets[0].data = counts;

Leave a comment