import { Component } from '@angular/core'; import * as Chart from 'chart.js';
@Component({ selector: 'app-page1', templateUrl: './page1.component.html', styleUrls: ['./page1.component.css'] }) export class Page1Component {
chart: any = [];
constructor() { }
ngOnInit() { this.chart = new Chart('myChart', { type: 'line', data: { labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], datasets: [{ label: 'My First dataset', data: [65, 59, 80, 81, 56, 55, 40], borderColor: '#3e95cd', fill: false }] }, options: { title: { display: true, text: 'Chart.js Line Chart - Custom Tooltip' } } }); }
}
import { Component } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; import * as Chart from 'chart.js';
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent {
constructor(private router: Router) { this.router.events.subscribe((event) => { if (event instanceof NavigationEnd) { setTimeout(() => { Chart.helpers.each(Chart.instances, (instance) => { instance.update(); }); }, 500); } }); }
}