Created
June 8, 2019 13:16
-
-
Save alistairjevans/c7ce67ab961974ffbd75792a75c74f6b to your computer and use it in GitHub Desktop.
Chart updates as data arrives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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