Chartjs-Angular 8 & ChartJS: Updating donut charts with HTTP Request data

0👍

Turns out that just overwriting the property does the trick:

loadChartData() {
        this.dataService.getData().subscribe(
            (response: any) => {
                const dataGroup1 = response.body.dataOne;
                const dataGroup2 = response.body.dataTwo;

                this.donutChartData = [
                    {
                        label: 'Group 1',
                        value: dataGroup1
                    },
                    {
                        label: 'Group 2',
                        value: dataGroup2
                    },
                ]
            }
        );
    }

I’m using angular-morris-js so it basically takes care of the update automatically. Hope that this helps another devs too.

Leave a comment