1👍
I assume you using latest ChartJS version. You need to a function to update data in Chartjs instance. Then pass it to setInterval
for realtime update.
const updateChartData = (chart, ajaxData) => {
const data = chart.data;
if (data.datasets.length > 0) {
//data.labels.push(<<LABEL YOUR WANT TO DISPLAY>>)
for (var index = 0; index < data.datasets.length; ++index) {
// data.datasets[index].data.push(<<PUSH DATA YOU WANT TO DISPLAY FROM ajaxData>>);
}
chart.update();
}
}
setInterval(() => {
const ajaxData = $.ajax(dataUrl).then(res => {
... // handle response
})
updateRealTime(myChart, ajaxData);
}, 1000);
Source:stackexchange.com