Refactor chart data generation into a helper