有人可以帮我弄清楚为什么我的json文件没有被生成。我使用了一小部分数据并且工作正常。当我使用完整集时,我得到的是空数组,前两行有效,或循环错误。
这是我的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
这是我从Generate (multilevel) flare.json data format from flat json
复制的脚本//load csv and copy to 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 the tree array
var tree = [];
nested_data.forEach(function(node) {
// add to parent
var parent = dataMap[node.parent];
if (parent) {
// create child array if it doesn't exist
(parent.children || (parent.children = []))
// add node to child array
.push(node);
} else {
// parent is null or missing
tree.push(node);
}
});
//create the root node for the treemap
var root = {};
// Add the data to the tree
root.name = "Start";
root.children = tree;
console.log(JSON.stringify(root,null, 4));
在创建树数组部分
之后看起来它出错了感谢任何帮助。谢谢!