Skip to content

Instantly share code, notes, and snippets.

@gparlakov
Last active May 16, 2022 03:55
Show Gist options
  • Save gparlakov/1deddf496a1d65dbbf38a3427f0c5a84 to your computer and use it in GitHub Desktop.
Save gparlakov/1deddf496a1d65dbbf38a3427f0c5a84 to your computer and use it in GitHub Desktop.
@Component({
template: `<canvas #canvas width="200" height="200"></canvas>`,
})
export class ChartComponent {
@ViewChild('canvas')
canvas: ElementRef | undefined;
chart: Chart | undefined;
constructor(private router: Router) {}
ngAfterViewInit() {
const data = [1, 2, 3, 4, 5];
this.chart = new Chart(this.canvas?.nativeElement, {
type: 'line',
data: {
datasets: [{ data, label: '1' }],
labels: ['1', '2', '3', '4', '5'],
},
options: {
onClick: (_, [element]) => {
if (element != null) {
this.router.navigate([data[element.index]]);
}
},
},
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment