Rahul Hindocha
Rahul Hindocha

Reputation: 215

How to access the Chart object in Javascript DOM?

I am drawing charts using chart.js. I am doing this dynamically and hence not storing the Chart objects in any Javascript variables and directly just rendering the charts at the run-time. Now I am thinking to build a feature for updating these charts. I know that for updating the charts, we need to use the .update() function. But I am not able to figure out how do I fetch the chart object.

Note: There are many charts on the webpage and new ones are constantly getting added with time. So it is not possible to store the chart objects for my implementation.

Upvotes: 2

Views: 1116

Answers (1)

wahab memon
wahab memon

Reputation: 2416

To access the chart instance, you can simply use Chart.instances which will return a key-value pair. Values containing the chart instance. You can refer this fiddle as reference.

Upvotes: 2

Related Questions