I am currently working on creating a dynamic grouped and stacked chart using D3js. I have multiple checkboxes that I utilize to group data based on various attributes. One of the grouping criteria is by two specific JSON
attributes: quantity
and type
. Here is an example of the 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 typical nest function:
var nest = d3.nest()
.key(function(d) { return d[groupBy]; });
<input type = "checkbox" name ="groupBy" value="someValue">
In this scenario, I aim to have three groups: 10 week, 3 month, and 12 month. I am attempting to create a separate case for nesting the data but am unsure how to make the key a combination of two attributes. My current attempt looks like this:
var nest = d3.nest();
if(groupBy === "specialValue"){ // groupBy represents the selected checkbox value
// need to create a key as a combination of quantity and type....but I'm not sure how to do it
groupBy = key;
nest.key(function(d) { return d[groupBy]; });
}
If anyone can provide assistance, I would greatly appreciate it.