[Chartjs]-How to use chart.js in angular 7

2👍

after installing chartjs via npm or what have you:

import { Chart } from 'chart.js';

app.component.ts

@ViewChild('revenueLineChart') chart: ElementRef;

ngAfterViewInit() { this.createChart() }

createChart() {
   const ctx = this.chart.nativeElement.getContext('2d');
   const revenueLineChart = new Chart(ctx, { // ... });
   // .. the rest of your settings
}

app.component.html

<canvas #revenueLineChart></canvas>

Leave a comment