I created a project with Django. I am using Chart.js in my index page. But when I look the console, there are several errors like:
(index):4078 Uncaught ReferenceError: doughnutChart is not defined
at (index):4078
I do not know how to solve it. Here is my code:
template.html
<canvas id="doughnutChart" ></canvas>
<script>
var myDoughnutChart = new Chart(doughnutChart, {
type: 'doughnut',
data: {
datasets: [{
data: ['{{ wait_senior_analyst|safe }}','{{ wait_lead|safe }}',
'{{ wait_manager|safe }}','{{ wait_regional_manager|safe }}',
'{{ wait_regional_director|safe }}','{{ wait_cfo|safe }}'],
backgroundColor: [ '#f6f349','#6def56',
'#e90d73','#7f00d9',
'#1df3f3','#ff7702']
}],
labels: [
'Senior Analyst',
'Lead',
'Manager',
'Regional Manager',
'Regional Director',
'CFO',
]
},
options: {
responsive: true,
legend : {
position: 'bottom',
labels: {
fontColor: {% if request.user.themeChoice == 'Light' %}"black"{% else %}"#d2fff2"{% endif %},
fontSize: 16
}
},
layout: {
}
}
});
</script>