{"action":"created","issue":{"url":"https://api.github.com/repos/dpgaspar/Flask-AppBuilder/issues/149","labels_url":"https://api.github.com/repos/dpgaspar/Flask-AppBuilder/issues/149/labels{/name}","comments_url":"https://api.github.com/repos/dpgaspar/Flask-AppBuilder/issues/149/comments","events_url":"https://api.github.com/repos/dpgaspar/Flask-AppBuilder/issues/149/events","html_url":"https://github.com/dpgaspar/Flask-AppBuilder/issues/149","id":68670657,"number":149,"title":"[Question]: Recommend way to implement a TimeSeries Chart?","user":{"login":"a-mckinley","id":5833029,"avatar_url":"https://avatars.githubusercontent.com/u/5833029?v=3","gravatar_id":"","url":"https://api.github.com/users/a-mckinley","html_url":"https://github.com/a-mckinley","followers_url":"https://api.github.com/users/a-mckinley/followers","following_url":"https://api.github.com/users/a-mckinley/following{/other_user}","gists_url":"https://api.github.com/users/a-mckinley/gists{/gist_id}","starred_url":"https://api.github.com/users/a-mckinley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/a-mckinley/subscriptions","organizations_url":"https://api.github.com/users/a-mckinley/orgs","repos_url":"https://api.github.com/users/a-mckinley/repos","events_url":"https://api.github.com/users/a-mckinley/events{/privacy}","received_events_url":"https://api.github.com/users/a-mckinley/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dpgaspar/Flask-AppBuilder/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-15T12:39:43Z","updated_at":"2015-04-15T20:56:39Z","closed_at":null,"body":"I have a simple model that stores a timestamp and associated number of elements.\r\n\r\n```\r\nclass Event(Model):\r\n        id = Column(Integer, primary_key=True)\r\n        number = Column(Integer)\r\n        time = Column(DateTime)\r\n```\r\n\r\nHow can I use DirectByChartView to display a binned time series representation of the aggregate of number during each time slice?\r\n\r\nDo I need to implement additional methods on my model to generate a binned \"view\" of the model?\r\n\r\nE.g:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/5833029/7158718/b1106c02-e374-11e4-8d5d-6c5ac3bdb9f3.png)\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dpgaspar/Flask-AppBuilder/issues/comments/93567213","html_url":"https://github.com/dpgaspar/Flask-AppBuilder/issues/149#issuecomment-93567213","issue_url":"https://api.github.com/repos/dpgaspar/Flask-AppBuilder/issues/149","id":93567213,"user":{"login":"dpgaspar","id":4025227,"avatar_url":"https://avatars.githubusercontent.com/u/4025227?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgaspar","html_url":"https://github.com/dpgaspar","followers_url":"https://api.github.com/users/dpgaspar/followers","following_url":"https://api.github.com/users/dpgaspar/following{/other_user}","gists_url":"https://api.github.com/users/dpgaspar/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgaspar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgaspar/subscriptions","organizations_url":"https://api.github.com/users/dpgaspar/orgs","repos_url":"https://api.github.com/users/dpgaspar/repos","events_url":"https://api.github.com/users/dpgaspar/events{/privacy}","received_events_url":"https://api.github.com/users/dpgaspar/received_events","type":"User","site_admin":false},"created_at":"2015-04-15T20:56:39Z","updated_at":"2015-04-15T20:56:39Z","body":"On your models.py (or where you have defined Event) import python's datetime then create a method to aggregate your time column (assuming hours):\r\n\r\n``` python\r\n\r\n    class Event(Model):\r\n        id = Column(Integer, primary_key=True)\r\n        number = Column(Integer)\r\n        time = Column(DateTime)\r\n\r\n        def hours(self):\r\n            return datetime.datetime(self.time.year, self.time.month, self.time.day, self.time.hour, 1)\r\n```\r\n\r\nThen define your direct chart view class (on views.py):\r\n\r\n``` python\r\nclass CountryDirectChartView(DirectByChartView):\r\n    datamodel = SQLAModel(CountryStats)\r\n    chart_title = 'Direct Data'\r\n\r\n    definitions = [\r\n        {\r\n            'label': 'Hourly',\r\n            'group': 'hours',\r\n            'series': ['number']\r\n        }\r\n    ]\r\n\r\n```\r\n\r\nI have not tested this so it's probably not 100% correct, but this is the general idea, tell me if it worked."}}