Created
October 12, 2013 23:45
-
-
Save alanb1501/6956255 to your computer and use it in GitHub Desktop.
Rolling up data with D3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = d3.nest() | |
.key(function(d) { | |
var dt = new Date(d.date); | |
var ret = [dt.getUTCFullYear(),dt.getUTCMonth()+1,dt.getUTCDate()]; | |
return ret.join('-'); | |
}) | |
.rollup(function(d) { | |
var sum = 0; | |
for(var i = 0; i < d.length; ++i) { | |
sum+= d[i].value; | |
} | |
return sum; | |
}) | |
.entries(data); | |
return arr.map(function(elm) { | |
return { | |
'value': elm.values, | |
'date': elm.key | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment