mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-28 21:02:45 +00:00
add updateData and removeAllData methods to donut chart
This commit is contained in:
parent
05f01a5d94
commit
7d59dc6c18
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user