Chartjs-ChartJS re-rendering bug

1👍

I prefer chart.update() over chart.destroy().

Here’s a small, simple example how I usually update data.

  1. I make one object per chart with labels (empty array) and data (empty array) and colors and all the stuff you need.
  2. I fill these arrays with data I get (AJAX).
  3. Optional: If I get all the data and need to filter it to show less data, I copy my object to keep all the data I got and have all the data I need now for my chart in another object
  4. Make an updateChart() function which alters your displayed data or saved data from your backup object or use new data from a new AJAX request.
  5. End your updateChart() with chart.update() (or whatever your chart is called).

Multiple charts shouldn’t be a problem and you shouldn’t have to destroy your chart.

Leave a comment