Perfected the query stmt used for making the chart