[Chartjs]-Change data onclick with ChartJS

1👍

Assuming dataUs and dataEu are arrays with values, you can access and change the data of your chart easily with javascript like this:

myChart.data.datasets[0].data = dataUs; // assuming dataUs is an array

After doing that you need to rerender the chart with

myChart.update();

Heres a fully functional CODEPEN EXAMPLE. Feel free to manipulate and play around with it.

Leave a comment