0
我有具有以下结构的JSON数据:D3叠代嵌套数据
var data = {
"from": 1457823600000,
"to": 1458687600000,
"equipments": [
{
"name": "Equipment1",
"actions": [
{
"name": "action1",
"start": 1458035704183,
"end": 1458122104234,
"color": "green"
},
{
"name": "action2",
"start": 1458035704268,
"end": 1458294904268,
"color": "red"
}
]
},
{
"name": "Equipment2",
"actions": [
{
"name": "action3",
"start": 1458208504268,
"end": 1458381304268,
"color": "blue"
},
{
"name": "action4",
"start": 1458122104268,
"end": 1458467704268,
"color": "yellow"
}
]
}
]
}
在D3 y轴应该是这样的:
Equipment 1 |
action1 |
action2 |
|
Equipment 2 |
action3 |
action4 |
|
-----------------------------
现在我的D3看起来像这样
var equipments = svg.selectAll("equipments")
.data(data.equipments)
.enter()
.append("text")
.attr("x", ...)
.attr("y", ...)
.text(name);
我可以在2个设备(Equipment1
和Equipment2
),但如何应对次迭代e设备的孩子?
这是否解决了您的问题?你可以验证这个anwser? – pltrdy