Accepted answer

code in component is correct, issue was in html wrapping the <canvas> tag inside <div> has solved the issue as said in comment by @quan vo


<div><canvas id="canvas"></canvas></div>

why <canvas> tag should be inside <div> tag, for this one can refer this article

in short:

the html5 canvas element is an html tag similar to the <div>, <a>, or <table> tag, with the exception that its contents are rendered with javascript. in order to leverage the html5 canvas, we'll need to place the canvas tag somewhere inside the html document, access the canvas tag with javascript, create a context, and then utilize the html5 canvas api to draw visualizations.

Related Query

More Query from same tag