This is a follow-up to another StackOverflow problem with creating charts with multiple CSVs into a single dc.js dashboard.
I followed the instructions and my charts are working. However, what is not working is the numberDisplay
elements. What I'm suspecting is that since I'm tabulating the totals of two CSVs, I would have to adjust the groupAll.reduceSum()
function, but I'm unsure how. An example of my code is below
//using queue.js to load data
var q = queue()
.defer(d3.csv, "data1.csv")
.defer(d3.csv, "data2.csv");
q.await(function(error, data1, data2){
//initiatizing crossfilter and 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 to sum up the values
var scoresGroup = ndx.groupAll().reduceSum(function(d) {
d.scores;
});
var totalGroup = ndx.groupAll().reduceSum(function(d) {
d.total;
});
//parameters for the number display. Currently it is 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 help would be greatly appreciated!
You need to use
return
in order to return values from functions!should be
Otherwise, you will end up summing
undefined
andundefined
is Not a Number. :-)