d3.js CSV data aggregation -


i want aggregate data read in csv. tried d3.nest , works not looking since converts data json structure. important thing me keep csv interface intact reusable charts work whether use raw or aggregated csv data. think great if 1 use map reduce aggregation.

for example convert this:

a,b,c 1,1,1 1,2,1 1,3,1 1,4,1 2,1,1 2,2,1 2,3,1 2,4,1 3,1,1 3,2,1 3,3,1 3,4,1 3,5,1 3,6,1 4,1,1 4,2,1 

into this:

a,d 1,4 2,4 3,6 4,2 

i tried out solution proposed adam pearce did not work since aggregates data string format. based on adams idea modified code bit. used nest aggregation , map data structure wanted. here came in end:

    var aggregated = d3.nest()         .key(function(d) {             var ts;             var key = new date(parseint(d.ms_since_epoch));             key.setminutes(0);             key.setseconds(0);             key.setmilliseconds(0);             return key.gettime();         })         .rollup(function(leaves) { return leaves.length; })         .entries(data)         .map(function(d) { return {'ms_since_epoch': d.key, 'requests_hour': d.values}; }) 

i'm not sure idea - might want decouple how you're reading data how you're displaying - creating csv d3.nest isn't complicated;

d3.nest()   .key(function(d){ return d.a; })   .rollup(function(leaves) { return leaves.length; })   .entries(data)   .map(function(d){ return d.key + ',' + d.values; })   .join("\n") 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -