Last active
May 16, 2022 03:55
-
-
Save gparlakov/1deddf496a1d65dbbf38a3427f0c5a84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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