If anyone's looking for similar functionality for PHP (Database-level time-grouping, time-ranged drilldowns, charts), you can check out http://razorflow.com
(Disclosure: I am the developer of RazorFlow, and am only posting here because I feel it's relevant to this particular story)
https://github.com/ankane/chartkick/blob/master/lib/chartkic...