I have a graph displaying real-time data. Over time the number of data points grows impractical to manage, so I have tried to "shave off" the invisible ones. Unfortunately, the animation isn't working right.
Desired outcome:

Actual outcome ("notice how the library thinks that the new data is unrelated to the old one, resulting in the points moving vertically, not horizontally):

This is the code that removes the old data:
const truncate = (data, length) => {
if (data.length > length) {
while (data.length >= length) {
data.shift();
}
}
return data;
}
Is there a way to get rid of the derpiness?