Make groupby for charts more dynamic