Style donut chart and add total count

This commit is contained in:
Jesse Lucas 2020-03-27 21:52:13 -04:00
parent 485a234263
commit 6158b20a8c
5 changed files with 27 additions and 3 deletions

View File

@ -20,9 +20,12 @@ export class DeviceChartComponent implements OnInit {
ngOnInit(): void { } ngOnInit(): void { }
ngAfterViewInit(): void { ngAfterViewInit(): void {
let totalCount: number = 0;
this.deviceService.getAll().subscribe( this.deviceService.getAll().subscribe(
device => { device => {
console.log("device", device); // Count the number of folders and set chart
totalCount++;
this.donutChart.count = totalCount;
// Get StateType and convert to string // Get StateType and convert to string
const stateType: Device.StateType = Device.getStateType(device); const stateType: Device.StateType = Device.getStateType(device);

View File

@ -1 +1,4 @@
<canvas id={{elementID}} width="200%" height="100%"></canvas> <div class="chart-container">
<canvas id={{elementID}} width="100%" height="100%"></canvas>
<div class="center">{{count}}</div>
</div>

View File

@ -0,0 +1,12 @@
.chart-container {
position: relative;
}
.center {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
font-size: 18px;
}

View File

@ -9,6 +9,7 @@ import { tooltip } from '../tooltip'
}) })
export class DonutChartComponent { export class DonutChartComponent {
@Input() elementID: string; @Input() elementID: string;
count: number;
private canvas: any; private canvas: any;
private ctx: any; private ctx: any;
@ -56,7 +57,6 @@ export class DonutChartComponent {
this.chart = new Chart(this.ctx, { this.chart = new Chart(this.ctx, {
type: 'doughnut', type: 'doughnut',
data: { data: {
labels: ["Up to Date", "Syncing", "Waiting to Sync", "Out of Sync", "Failed Items"],
datasets: [{ datasets: [{
data: [], data: [],
backgroundColor: [ backgroundColor: [
@ -68,6 +68,7 @@ export class DonutChartComponent {
}] }]
}, },
options: { options: {
cutoutPercentage: 70,
responsive: false, responsive: false,
legend: { legend: {
display: false display: false

View File

@ -22,8 +22,13 @@ export class FolderChartComponent implements OnInit {
} }
ngAfterViewInit() { ngAfterViewInit() {
let totalCount: number = 0;
this.folderService.getAll().subscribe( this.folderService.getAll().subscribe(
folder => { folder => {
// Count the number of folders and set chart
totalCount++;
this.donutChart.count = totalCount;
// Get StateType and convert to string // Get StateType and convert to string
const stateType: Folder.StateType = Folder.getStateType(folder); const stateType: Folder.StateType = Folder.getStateType(folder);
const state: string = Folder.stateTypeToString(stateType); const state: string = Folder.stateTypeToString(stateType);