[Chartjs]-Display multiple chart.js charts using for loop in Django template

2๐Ÿ‘

โœ…

So in order to reference the canvas, I appended the forloop index to the canvas id:

<canvas id="myChart{{ forloop.counter0 }}" width="600" height="400">

And then to reference the canvas within the chart.js context:

var ctx = document.getElementById("myChart" + {{ forloop.counter0 }}).getContext('2d'); 

0๐Ÿ‘

A way for showing multiple charts in one canvas is using Mixed Chart.

more info :

https://www.chartjs.org/docs/latest/charts/mixed.html

Leave a comment