A simple workaround is to add another parameter to your function to distinguish your charts from each other.
I decided to use a chart id for this, so you are sure you will not affect the other.
First you need to slightly modify your function:
Now, when you call your function, do not forget about id:
// ids need to be 0, 1, 2, 3 ... drawChart(ctxElement, ctxType, ctxDataLabels, ctxDataSets, "Canvas 1", 0); drawChart(ctxElement, ctxType, ctxDataLabels, ctxDataSets, "Canvas 2", 1); drawChart(ctxElement, ctxType, ctxDataLabels, ctxDataSets, "Canvas 3", 2);
You can see a fully working example of this script (with 3 diagrams), and here is a preview:

source share