Skip to content

Instantly share code, notes, and snippets.

@alanb1501
Created October 12, 2013 23:45
Show Gist options
  • Save alanb1501/6956255 to your computer and use it in GitHub Desktop.
Save alanb1501/6956255 to your computer and use it in GitHub Desktop.
Rolling up data with D3
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