Moving chart code to a service to be called by the controller.