working code on averages for overview chart