Refactored the anim function in order to make it work for each type of chart