Splitted Chart-Code into different functions. Not working though.