Generifying the pie chart code