Chartjs-Charts.js not loading in Django

0👍

That’s because your canvas element is not loaded yet, wrap your main.js code in DOMContentLoaded callback function

document.addEventListener('DOMContentLoaded', function(){ 
    // wrap your js code here
}, false);

// with jQuery 
$(document).ready(function(){ /* ... */ });

// shorter
$(function(){ /* ... */ });

Update

Also check your js code

let ctx = document.getElementById('pie-chart').getContext('2d');
let chart1 = new Chart(ctx, config);

Leave a comment