optimized piechart code