1

I am trying to follow the various instructions (e.g. How to convert to D3's JSON format?) to create a collapsible tree with D3.js.

Here is what I have done so far: http://jsfiddle.net/L3phF/6/

I have a problem when using nest() as console.log(nest) shows me only an empty object, but I cannot find the error.

var raw = d3.select("#csvdata").text();

var parsed = d3.csv.parse(raw);

// d3.select("#parsed").text(raw); 
// d3.select("#parsed").text(JSON.stringify(parsed));

var data = JSON.stringify(parsed);

var nest = d3.nest()
    .key(function(d) { return d.subgroup; })
    .key(function(d) { return d.division; })
    .key(function(d) { return d.product; })
    .entries(data);

console.log(nest);

I appreciate any help!

Community
  • 1
  • 1
majom
  • 7,863
  • 7
  • 55
  • 88

1 Answers1

2

Don't turn the nice object d3.csv.parse gives you back into a string! d3.nest() is expecting an object, not a string:

var nest = d3.nest()
    .key(function(d) { return d.subgroup; })
    .key(function(d) { return d.division; })
    .key(function(d) { return d.product; })
    .entries(parsed);

will give you what you want.

Adam Pearce
  • 9,243
  • 2
  • 38
  • 35