javascript - dc.js: ReduceSum with multiple CSVs -


this follow-up stackoverflow problem creating charts multiple csvs single dc.js dashboard.

i followed instructions , charts working. however, not working numberdisplay elements. i'm suspecting since i'm tabulating totals of 2 csvs, have adjust groupall.reducesum() function, i'm unsure how. example of code below

//using queue.js load data var q = queue()   .defer(d3.csv, "data1.csv")   .defer(d3.csv, "data2.csv");    q.await(function(error, data1, data2){    //initiatizing crossfilter , ingesting data   var ndx = crossfilter();   ndx.add(data1.map(function(d){     return { age: d.age,              gender: d.gender,              scores: +d.scores,              total: +d.total,              type: 'data1'};     }));    ndx.add(data2.map(function(d){     return { age: d.age,              gender: d.gender,              scores: +d.scores,              total: +d.total,              type: 'data2'};     }));  //initializing charts totaldisplay = dc.numberdisplay("#total-display"); totalscores = dc.numberdisplay("#total-scores");  //groupall function sum values var scoresgroup = ndx.groupall().reducesum(function(d) {           d.scores;         });         var totalgroup = ndx.groupall().reducesum(function(d) {            d.total;         });  //parameters number display. returning nan totaldisplay         .formatnumber(d3.format(","))         .valueaccessor(function(d) {             return d;         })         .group(totalgroup);  totalscores         .formatnumber(d3.format(",f"))         .valueaccessor(function(d) {             return d;         })         .group(scoresgroup); 

any appreciated!

you need use return in order return values functions!

var scoresgroup = ndx.groupall().reducesum(function(d) {       d.scores; }); var totalgroup = ndx.groupall().reducesum(function(d) {        d.total; }); 

should be

var scoresgroup = ndx.groupall().reducesum(function(d) {       return d.scores; }); var totalgroup = ndx.groupall().reducesum(function(d) {        return d.total; }); 

otherwise, end summing undefined , undefined not number. :-)


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -