Made rendering the chart a function