diff --git a/src/app/charts/donut-chart/donut-chart.component.ts b/src/app/charts/donut-chart/donut-chart.component.ts index 5555ea7e8..e75adf556 100644 --- a/src/app/charts/donut-chart/donut-chart.component.ts +++ b/src/app/charts/donut-chart/donut-chart.component.ts @@ -1,5 +1,6 @@ import { Component, Input } from '@angular/core'; import { Chart } from 'chart.js' +import { LabelOptions } from '@angular/material/core'; @Component({ selector: 'app-donut-chart', @@ -23,6 +24,16 @@ export class DonutChartComponent { } } + updateData(data: { label: string, count: number }[]): void { + //Using object destructuring + for (let i = 0; i < data.length; i++) { + let s = data[i]; + this.chart.data.labels[i] = s.label; + this.chart.data.datasets[0].data[i] = s.count; + } + this.chart.update(); + } + addData(data: number): void { // this.chart.data.labels.push(label); this.chart.data.datasets.forEach((dataset) => { @@ -31,6 +42,14 @@ export class DonutChartComponent { this.chart.update(); } + removeAllData(withAnimation: boolean): void { + this.chart.data.labels.pop(); + this.chart.data.datasets.forEach((dataset) => { + dataset.data = []; + }); + this.chart.update(withAnimation); + } + ngAfterViewInit(): void { this.canvas = document.getElementById(this.elementID); this.ctx = this.canvas.getContext('2d');