you might need to have for ... in loops to build that object in your innercolumns like this:

itemlookup= data[0],
category = d3.keys(itemlookup.category),
items = d3.keys(itemlookup.category[type1[0]]),
columnheaders = [],
innercolumns = (function(){
  var result = {};
  for(var i = 0, ii = category.length; i<ii; i++){
    var holder = [];
    for(var j = 0, jj = items.length; j<jj; j++){
      result[category[i]] = holder;
  return result;

you can refer to this for reference:


i have tried to achieve grouped stacked bar chart using d3.stack(). here are 2 important parts of my solution:

var datasets=[d3.stack().keys(['type1','type3'])(data),

var num_groups=datasets.length;

here i am using .keys() method of d3.stack to create datasets for each group. after this we can use the code for creating stacked bar chart like this:

d3.range(num_groups).foreach(function(gnum) {
                .attr('class', 'group'+gnum)

you can see the complete solution here:

Related Query