I have this table:
Table "public.transaction"
Column | Type | Modifiers
------------+-----------------------------+----------------------------------------------------------
id | integer | not null default nextval('transaction_id_seq'::regclass)
account_id | integer |
note | character varying |
date | timestamp without time zone |
amount | numeric |
it contains transactions in the format:
id | account_id | note | date | amount
----+------------+----------------------------------+---------------------+--------
1 | 1 | Loopia AB | 2013-02-07 00:00:00 | -178
2 | 1 | ÅSGATAN 2 KÖK & | 2013-02-07 00:00:00 | -226
3 | 1 | BURGER KING ODEN | 2013-02-06 00:00:00 | -89
4 | 1 | OLEARYS 917 | 2013-02-06 00:00:00 | -309
5 | 1 | TAXI STOCKHOLM | 2013-02-06 00:00:00 | -875
6 | 1 | GRET INDIAN REST | 2013-02-06 00:00:00 | -85
8 | 1 | VIDEO RULLEN | 2013-02-04 00:00:00 | -169
9 | 1 | ICA SUPERMARKET | 2013-02-04 00:00:00 | -196
10 | 1 | ICA SUPERMARKET | 2013-02-03 00:00:00 | -110
I then feed the data to D3 in the following format:
[
{
"note": "TEXAS LONGHORN",
"date": "2013-01-10T00:00:00",
"amount": 110,
"id": 74,
"account_id": 1
},
{
"note": "GOOGLE *FEO Medi",
"date": "2013-01-10T00:00:00",
"amount": 22,
"id": 73,
"account_id": 1
},
{
"note": "Pressbyran 5122",
"date": "2013-01-10T00:00:00",
"amount": 13,
"id": 77,
"account_id": 1
},
{
"note": "ICA SUPERMARKET",
"date": "2013-01-10T00:00:00",
"amount": 106,
"id": 76,
"account_id": 1
},
{
"note": "HÅR 3000",
"date": "2013-01-10T00:00:00",
"amount": 345,
"id": 75,
"account_id": 1
},
{
"note": "Pressbyran 5122",
"date": "2013-01-11T00:00:00",
"amount": 19,
"id": 72,
"account_id": 1
},
{
"note": "BIRKA PUNKTEN",
"date": "2013-01-11T00:00:00",
"amount": 79,
"id": 71,
"account_id": 1
}
]
D3 streamgraphs however requires that all the data points are present. Thus I have to put all the dates, even those without any transactions, in the data that I feed to D3.
I would love your input on how to make this effiently with any of the tools available. You can play around with a live example at http://bl.ocks.org/joar/4747134/a702cf79bf10b1438cc665a2438b3f5cf9ab8bf0
You want to
generate_seriesa set of dates covering the target region, then left outer join your transaction table against it. See this SQLFiddle example.You can generate the desired data format with PostgreSQL’s json functions, as per this SQLFiddle.
… though I haven’t tested feeding it into the graphing tool.