Tutorial 18: Simple javascript closure example with dc.js charts

working code

 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

Popular posts from this blog

Tumblr posts about sexplanation, DoeEyes and Dr. Lindsay Doe

बैगन

Type of Common Charts used in visualization