Rails: Using groupdate & chartkick to create a cumulative user graph
It's because you need to sort before you do the cumulative sum.
Try this:
sum=0
User.group_by_day(:created_at).count.to_a.sort{|x,y| x[0] <=> y[0]}.map { |x,y| { x => (sum += y)} }.reduce({}, :merge)
Martin's answer was close, but I ended up using:
User.group_by_week(:created_at).order("week asc").count.map { |x,y| { x => (sum += y)} }.reduce({}, :merge)
To get weekly - notice the order("week asc") - it's what fixed it...