Try to fix stat pies

This commit is contained in:
Torjus Håkestad 2021-04-10 15:21:38 +02:00
parent 735114edbd
commit ecfbf43b24

View File

@ -1,7 +1,7 @@
<template>
<div class="stats-container" :class="containerClass">
<h2>{{ title() }}</h2>
<div class="chart-container">
<div class="chart-container" :class="chartClass">
<canvas id="chart" widht="400" height="400"></canvas>
</div>
</div>
@ -37,6 +37,9 @@ export default class StatsPie extends Vue {
containerClass(): string {
return `stats-container-${this.statType}`;
}
chartClass(): string {
return `chart-container-${this.statType}`;
}
mounted(): void {
const url = `/api/stats?type=${this.statType}&limit=10`;
@ -47,7 +50,9 @@ export default class StatsPie extends Vue {
}
renderPie(): void {
const elem = document.getElementById('chart') as HTMLCanvasElement;
const elem = document.getElementById(
this.chartClass(),
) as HTMLCanvasElement;
const ctx = elem.getContext('2d') as CanvasRenderingContext2D;
const sortedStats = this.stats.sort();
const values = sortedStats.map((s) => s.count);