[Chartjs]-Error with Chart.js : TypeError: t is undefined

4👍

Solved, apparently the script link I was using was bugged. Changed it to https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js and it works fine. See Chris G‘s comment.

2👍

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.

1👍

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

Leave a comment