Range Slider and Selector

With the range slider and selector example showed here: https://plot.ly/javascript/range-slider/
I need to keep adding data to it. I’m currently doing this with set interval method. However, I also want the graph only display 20 data on the plot. That is, if there are 21 data, the graph will auto scroll to the left, and the first data will disappear on the graph. if I zoom out or use the range slider function, I should then see them all.
The problem is I don’t know how to force the graph only shows 20 data, should I change the graph’s property or the slider’s property or something else? (I’m thinking my be I could force auto panning?)

Dynamically modify the Range has one possible solution.

great, thank you very much!