0👍
Assuming the data you get back from that ajax call is good, you should be fine with just replacing the
myChart.data.datasets[0].data.push(getRandomIntInclusive(1, 25));
with
myChart.data.datasets[0].data.push(data);
Of course this is dependent on the format of that data when it gets back to you.
I recommend console.log-ing that data once it gets back from the ajax to make sure it’s in a format suitable for chartjs
0👍
Let’s say, moist = [50, 30]
and the content of the JSON response is as follows:
data{"id":"1" , "val":"20"}
To update moist
from [50,30]
to [1, 20]
:
myChart.data.datasets[0].data[0] = data.id;
myChart.data.datasets[1].data[1] = data.val;
myChart.update();
Source:stackexchange.com