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

More Query from same tag