2

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.

3
  • See if you can use "refs" to keep track of each chart and update them accordingly. Commented May 30, 2021 at 13:09
  • What is "refs"? Can you please share any articles or other resource. Commented May 30, 2021 at 13:13
  • Either this if you're using react or just a plain old getElementById() for vanilla JavaScript. Add ID's to each chart and then you can retrieve each singular instance using those IDs Commented May 30, 2021 at 13:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.