moving logic  behind charts to functions

moving logic behind charts to functions for pie charts, line charts and
bar charts.