-2
window.onload = function() {
    var ctx = document.getElementById('chart-area').getContext('2d');
    window.myDoughnut = new Chart(ctx, config);
};

When window load that time may chart function is not working and error was accrued "can't read property "getcontext" of null.

Hemansi
  • 1
  • 2
  • 1
    At the time the code runs, `document.getElementById('chart-area')` is null / isn't finding anything. Do you have the correct `id` or are you creating the id after your code runs? – freedomn-m Dec 09 '20 at 14:09

1 Answers1

0

Try with this one :

document.onreadystatechange = function() {
    if(document.readyState == "complete") {

        //document is ready . Do you stuff here
    }
}

source : DOM - readyState