Fixed queries and loops for charts