[Chartjs]-How to retrieve ChartJS instance after initialization

27👍

Just loop through Chart.instances

Chart.helpers.each(Chart.instances, function(instance){
  alert(instance.chart.canvas.id)
})

Fiddle – http://jsfiddle.net/bkq5Lq8b/

0👍

If someone doesn’t want to iterate over instances array, then he can get instance directly from id like this.

const chart = Chart.getChart("canvas-id"); //where canvas-id is the id of a canvas

So now chart is your instance on which you can do the other operations. Reference here

Leave a comment