Skip to content

Instantly share code, notes, and snippets.

@alistairjevans
Created June 8, 2019 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alistairjevans/c7ce67ab961974ffbd75792a75c74f6b to your computer and use it in GitHub Desktop.
Save alistairjevans/c7ce67ab961974ffbd75792a75c74f6b to your computer and use it in GitHub Desktop.
Chart updates as data arrives
connection.on("newData", function (time, speed, count) {
// This subtract causes the data to be placed
// in the centre of the chart as it arrives,
// which I personally think looks better...
var dateValue = moment(time).subtract(5, 'seconds');
speedValue.innerText = speed;
countValue.innerText = count;
// append the new data to the existing chart data
myChart.data.datasets[0].data.push({
x: dateValue,
y: speed
});
// update chart datasets keeping the current animation
myChart.update({
preservation: true
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment