我想复制 Mike Bostock 的可折叠树图形 ( http://bl.ocks.org/mbostock/4339083 )。
我已经nest
使用d3.js
. 现在,数据如下所示:
[
{
"key": "Bayer HealthCare",
"values": [
{
"key": "Animal Health",
"values": [
{
"key": "Companion Animal",
"values": [
{
"brand": "Drontal",
"product": "Companion Animal",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
},
{
"brand": "Profender",
"product": "Companion Animal",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
},
{
"brand": "Rompun",
"product": "Companion Animal",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
}
]
},
{
"key": "Companion Animal - Food Animal Product",
"values": [
{
"brand": "Baytril",
"product": "Companion Animal - Food Animal Product",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
}
]
},
{
"key": "Companion animals",
"values": [
{
"brand": "Advantage",
"product": "Companion animals",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
},
{
"brand": "Advantix",
"product": "Companion animals",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
},
{
"brand": "Advocate",
"product": "Companion animals",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
}
]
},
{
"key": "Food Animal Product",
"values": [
{
"brand": "Baycox",
"product": "Food Animal Product",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
},
{
"brand": "Catosal",
"product": "Food Animal Product",
"subgroup": "Bayer HealthCare",
"division": "Animal Health"
}
]
}
]
}
.....
(完整的数据和我到目前为止所做的可以在这里找到:http: //jsfiddle.net/L3phF/9/)
不幸的是,我不知道如何将数据转换为像https://gist.github.com/mbostock/1093025这样的“FLARE JSON”格式。如果是对的,我必须将“key”重命名为“name”,将“values”重命名为“children”,并且我必须在最低级别的每个对象前面插入“”name:“”。
我很感激任何帮助!