Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve ChartJS instance after initialization

I'm using (have to) a framework that will eventually create a Chart with ChartJS, but it doesn't give me the instance of the chart.

Is there a way of retrieving this instance having only the canvas Id?

like image 487
Caio Franco Barreiro Avatar asked Apr 13 '16 19:04

Caio Franco Barreiro


People also ask

How do I destroy Chartjs?

destroy() Use this to destroy any chart instances that are created. This will clean up any references stored to the chart object within Chart. js, along with any associated event listeners attached by Chart.


1 Answers

Just loop through Chart.instances

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

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

like image 88
potatopeelings Avatar answered Oct 05 '22 21:10

potatopeelings