javascript - csv to json for hierarchy tree d3.js -


can me figure out why json file isn't being produced. used small subset of data , worked. when use full set either , empty array, first 2 lines worked, or cyclic error.

here first few lines of csv....

parent,name,nsize,lsize,type,level,nfill nr2f2,nnmt,20,3.035224474,black,red,blue nr2f2,cdh6,20,2.497522953,black,red,blue nr2f2,lox,20,2.882828876,black,red,blue nr2f2,afap1l2,20,3.250988851,black,red,blue nr2f2,kcng1,20,1.871023523,black,red,blue nr2f2,thbs2,20,3.556420832,black,red,blue nr2f2,rhou,20,4.892457573,black,red,blue nr2f2,itih5,20,1.579040121,black,red,blue 

and here script i've copied generate (multilevel) flare.json data format flat json

//load csv , copy global variable   d3.csv("../jsfiles/nr2f2tbx5hey2json.csv", function(csv_data) {          var nested_data =  d3.nest()           .entries(csv_data);  var datamap = {}; var datamap = nested_data.reduce(function(map, node) { map[node.name] = node; return map; }, {});  // create tree array var tree = []; nested_data.foreach(function(node) { // add parent var parent = datamap[node.parent]; if (parent) {     // create child array if doesn't exist     (parent.children || (parent.children = []))         // add node child array         .push(node); } else {     // parent null or missing     tree.push(node); }  });   //create root node treemap var root = {};      // add data tree root.name = "start"; root.children = tree; console.log(json.stringify(root,null, 4)); 

it looks errors out after //create tree array section

any appreciated. thanks!


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -