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