0👍
✅
Chart.js docs:
https://www.chartjs.org/docs/latest/developers/updates.html
On button click you would incorporate this code
chart.data.labels.push(label);
chart.data.datasets.forEach((dataset) => {
dataset.data.push(data);
});
chart.update();
Then to remove your other chart you would use chart.destroy().
Alternatively, you could load the data of the chart initially and change the visibility of the data series you want to show when clicked to none and set the old chart visibility to none. This would be lighter on clients if you are using large amounts of data sets and is easier to control when using jQuery’s .toggle() function.
https://www.chartjs.org/docs/3.0.0-alpha/developers/api.html
Source:stackexchange.com