Chartjs-Chart.js addData is undefined when using SignalR

3👍

According to the documentation you should change your dataset directly and call update:

.update(duration, lazy) function to update your datas

// duration is the time for the animation of the redraw in miliseconds
// lazy is a boolean. if true, the animation can be interupted by other animations
myLineChart.data.datasets[0].data[2] = 50; // Would update the first dataset's value of 'March' to be 50
myLineChart.update(); // Calling update now animates the position of March from 90 to 50.

I did a little test function on this fiddle:

setInterval(function(e) {
console.log(myDoughnutChart.data.datasets[0]);
  myDoughnutChart.data.datasets[0].data.push(15);
  myDoughnutChart.update();
}, 1000);

https://jsfiddle.net/Tintin37/weLoqyby/

Opened issue : https://github.com/chartjs/Chart.js/issues/1997

EDIT

For real time chart (I’m using signalr too, I use visjs)

http://visjs.org/examples/graph2d/15_streaming_data.html

Have a great day !

Leave a comment