Tutorial 18: Simple javascript closure example with dc.js charts
working code
Not working
Working
var group1 = dateDimension.group().reduceSum(function(d) { return d.dd; });
var group2 = dateDimension.group().reduceSum(function(d) { return d.count; });
Not working
var groups = {};
var columns = ["dd","count"];
for (var i = 0; i < columns.length; ++i) {
var col = columns[i]
groups[col] = dateDimension.group().reduceSum(function(d) { return d[col]; });
}
Working
for (var i = 0; i < columns.length; ++i) {
(function( columnName ) {
group[ columnName ] = dateDimension.group().reduceSum(function(d) { return d[columnName]; });
})( columns[i] );
}
Comments
Post a Comment