Moving duplicated js chart code to a new js file