As Saverio already mentioned, please start a new thread because this thread is about charts and you talk about graphs.
Unlike charts, graphs don't retain any history, so you need to keep the history with your own code, e.g. in a shift register.
(Also, the example you have posted makes very little sense. Please tell us what exactly you are trying to do)