Added a bunch of stuff
This commit is contained in:
54
src/components/chart/chart.component.ts
Normal file
54
src/components/chart/chart.component.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import {
|
||||
AfterViewInit,
|
||||
Component,
|
||||
ElementRef,
|
||||
OnDestroy,
|
||||
ViewChild,
|
||||
} from '@angular/core';
|
||||
import { Chart, ChartOptions } from 'chart.js';
|
||||
import { PluginNodata } from './plugin-nodata';
|
||||
import { PluginMoreColors } from './plugin-more-colors';
|
||||
import { ChartType, IData } from './chart-type';
|
||||
|
||||
@Component({
|
||||
selector: 'fbi-chart',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './chart.component.html',
|
||||
styleUrl: './chart.component.scss',
|
||||
})
|
||||
export class ChartComponent implements AfterViewInit, OnDestroy {
|
||||
@ViewChild('chart') canvas!: ElementRef;
|
||||
|
||||
private chart: any = undefined;
|
||||
private data: IData = {
|
||||
labels: [],
|
||||
labelsSource: [],
|
||||
datasets: [],
|
||||
};
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.initChart();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.chart?.destroy?.();
|
||||
}
|
||||
|
||||
initChart() {
|
||||
this.chart?.destroy?.();
|
||||
|
||||
const opts: ChartOptions = {};
|
||||
opts.responsive = true;
|
||||
opts.maintainAspectRatio = false;
|
||||
|
||||
this.chart = new Chart(this.canvas.nativeElement, {
|
||||
type: ChartType.Bar,
|
||||
data: this.data,
|
||||
options: opts,
|
||||
plugins: [PluginNodata.config(), PluginMoreColors.config()] as any[],
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user