How can we join multiple crossfilter in dc.js

699 views
Skip to first unread message

Aashu Sharma

unread,
Jan 29, 2016, 12:15:47 AM1/29/16
to dc-js user group
There are two data-sets, both are having one common column (like : id ) for join two data-set. so, how can i join two crossfilter data-sets.
ex :-

 var data1 = {"university":[{"cid":"11","id":"123","status":"verygood"},
                             {"cid":"12","id":"124","status":"good"},
                             {"cid":"13","id":"125","status":"average"},
                             {"cid":"14","id":"126","status":"good"},
                             {"cid":"15","id":"127","status":"bad"},
                             {"cid":"16","id":"128","status":"bad"},
                             {"cid":"17","id":"129","status":"verygood"},
                             {"cid":"18","id":"130","status":"bad"}] };   
                             
  var data2 = {"college":[{"cid":"11","cname":"IIT","cloc":"delhi"},
                          {"cid":"12","cname":"IIM","cloc":"bangalore"},
                          {"cid":"14","cname":"NIT","cloc":"patna"},
                          {"cid":"15","cname":"ISM","cloc":"dhanbad"},
                          {"cid":"16","cname":"JNU","cloc":"delhi"},
                          {"cid":"18","cname":"SRM","cloc":"chennai"}] };

Gordon Woodhull

unread,
Feb 8, 2016, 2:40:57 PM2/8/16
to dc.js user group
I trust you found this:

The other options is just implementing a boring join in javascript. In your case I guess cid is the unique key, so probably the easiest way is something like (untested):

var joined = {};

data1.university.forEach(function(u) {
joined[u.cid] = u;
});

data2.college.forEach(function(u) {
// if you have jQuery, $.extend would be a more succinct way to do this part:
joined[u.cid].cname = u.cname;
joined[u.cid].cloc = u.cloc;
});

var joined2 = [];
for(var cid in joined) {
joined2.push(joined[cid]);
}


--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/c1e1b5cf-868d-4512-aa40-2adffeecc3bb%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages