There are several versions of the script above. Finished scripts and graphs tailored to your use isn’t the purpose of the forum. See this post for more.
I am locking this thread out now to prevent continued chatter on something which a solution and 4 years of history.
If you get stuck with your own development start a new topic that includes sample data set to work with and the work you’ve tried to this point.