[Chartjs]-Impossible to render multiple charts with chart.js

1👍

This reason why it­‘s not working is because, you are storing all the chart instances to a single variable (myChart), which distorts all other chart instances, except one.

To resolve this …

add another parameter to the reCreateDataviz function ( for instance –
chartID
), which will contain an unique id for each chart :

var reCreateDataviz = function(canvas, previousDataviz, chartID) {
  ...
}

then, declare the variable, that stores the chart instance, like this :

window['myChart' + chartID] = new Chart(canvas, previousDataviz);

and finally, when calling reCreateDataviz function inside the for loop, pass i as the third argument, like so :

...
reCreateDataviz(canvas, data, i);
...

Leave a comment