samedi 25 octobre 2014

How to create a grouping by two JSON attributes in D3js


Vote count:

0




I'm trying to build a dynamic grouped and stacked chart using D3js. I have several check boxes, which I use to group the data according to different data attributes. One of the grouping is by two JSON attributes: quantity and type. I have the following JSON data:



[ {

"period":201408, "quantity":10, "type":"week", "sum":55.5 }, {

"period":201408, "quantity":3, "type":"month", "sum":150 }, {

"period":201408, "quantity":12, "type":"month", "sum":150 } ]



This is my ordinary nest function:



var nest = d3.nest()
.key(function(d) { return d[groupBy]; });

<input type = "checkbox" name ="groupBy" value="someValue">


So, in this case I should have three groups: 10 week, 3 month and 12 month. I'm trying to make a separate case to nest the data, but I don't know how to make the key to be a combination of two attributes. I'm doing something like:



var nest = d3.nest();
if(groupBy === "specialValue"){ // groupBy is the value of the selected checkbox
// get a key - combination of quantity and type....I don't know how
groupBy = key;
nest.key(function(d) { return d[groupBy]; });
}


Can somebody help me?



asked 46 secs ago







How to create a grouping by two JSON attributes in D3js

Aucun commentaire:

Enregistrer un commentaire