0

why my code gives an error of... Cannot read property 'getContext' of null... please help anyone.. Every possible things done, l

const ctx = document.getElementById("axes_line_chart").getContext("2d");

14th Aug 2021, 3:18 PM
Gaurav 20
Gaurav 20 - avatar
4 Respostas
0
Can we see the whole code?
14th Aug 2021, 3:21 PM
Brain & Bones
Brain & Bones - avatar
0
the only suggestion i can give you base on your current code is to use `?.` operator if it did'nt work please show more parts of your code const ctx = document.getElementById("axes_line_chart")?.getContext("2d");
14th Aug 2021, 3:22 PM
Nima
0
Gaurav 20 Double check that the parameter to getElementById() is the same as your canva's id
14th Aug 2021, 3:43 PM
Giorgos
0
Wrap it into a function like this. window.onload = function() { const ctx = document.getElememtById(“your canvas id”).getContext(“2d”); };
15th Aug 2021, 12:13 AM
Anthony Johnson
Anthony Johnson - avatar