[Chartjs]-Chart.js not getting rendered inside ng-template in angular

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.

Leave a comment