admin管理员组文章数量:1332108
I have a csv with the following data:
world,country,state
World,US,CA
World,US,NJ
World,INDIA,OR
World,INDIA,AP
World,INDIA,TN
I need to convert in to a tree hierarchy as shown below:
{
"name": "World",
"children": [
{ "name": "US",
"children": [
{ "name": "CA" },
{ "name": "NJ" }
]
},
{ "name": "INDIA",
"children": [
{ "name": "OR" },
{ "name": "TN" },
{ "name": "AP" }
]
}
]
};
Then this tree will be used for tree visualization. Can any one help on this?
I have a csv with the following data:
world,country,state
World,US,CA
World,US,NJ
World,INDIA,OR
World,INDIA,AP
World,INDIA,TN
I need to convert in to a tree hierarchy as shown below:
{
"name": "World",
"children": [
{ "name": "US",
"children": [
{ "name": "CA" },
{ "name": "NJ" }
]
},
{ "name": "INDIA",
"children": [
{ "name": "OR" },
{ "name": "TN" },
{ "name": "AP" }
]
}
]
};
Then this tree will be used for tree visualization. Can any one help on this?
Share Improve this question edited Nov 21, 2012 at 14:29 user142162 asked Nov 21, 2012 at 14:11 user1842231user1842231 2131 gold badge3 silver badges8 bronze badges1 Answer
Reset to default 7d3.nest is your friend!
Look at the Nest documentation for D3: https://github./d3/d3-collection/blob/master/README.md#nests
And here are some example I wrote when I was learning to use nest: https://gist.github./3176159
This question also helps: D3: use nest function to turn flat data with parent key into a hierarchy
本文标签: javascriptCreate hierarchy from csv in d3jsStack Overflow
版权声明:本文标题:javascript - Create hierarchy from csv in d3.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742228112a2436706.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论