i'm using 2.8.0 (current latest). earlier versions as suggested here did not help.

the solution to this error for me was providing the correct element id for the context. i was giving new chart() "chartjs-1" because i blindly copied an example, but my canvas id was "mycanvas". giving new chart() the actual id of my canvas fixed the problem.

note, the error in the question is from firefox. chrome gave a different error that clued me into the real culprit: cannot read property 'length' of null


put the javascript code (start with <script type="text/javascript">var ctx ...</script>) after the canvas element. this ensures that the canvas element is already present at the time when it gets referenced by var ctx = document.getelementbyid("mychart");

this should solve your problem.


solved, apparently the script link i was using was bugged. changed it to and it works fine. see chris g's comment.

Related Query