2π
β
It seems like that because you are using trying to plot the chart in a sub template it is not available known in the ngOnInit
hook. You can see this by trying to log document.getElementById('canvas')
, this will return null. If you change to the ngAfterViewInit
hook to create the chart it works fine:
https://stackblitz.com/edit/angular-chartjs-barchart-uqqnay?file=src%2Fapp%2Fapp.component.ts
0π
Try updating your template and wrap your canvas-element inside a div. Donβt know the cause to it but the problem seems to appear when the canvas-element is at the root of the template html.
Source:stackexchange.com