1👍
I prefer chart.update()
over chart.destroy()
.
Here’s a small, simple example how I usually update data.
- I make one object per chart with labels (empty array) and data (empty array) and colors and all the stuff you need.
- I fill these arrays with data I get (AJAX).
- 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
- 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. - 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.
- Chartjs-Why are more columns on one labels in Angular ChartJS?
- Chartjs-Can't render two charts on the same page from chart.js
Source:stackexchange.com