0
我想使用D3創建一組圖形,並且我很難弄清楚如何在我的JSON中訪問嵌套的數據結構。數據看起來是這樣的(部分):在D3中訪問嵌套的JSON結構
{ "date": "20120927",
"hours": [
{ "hour": 0, "hits": 823896 },
{ "hour": 1, "hits": 654335 },
{ "hour": 2, "hits": 548812 },
{ "hour": 3, "hits": 512863 },
{ "hour": 4, "hits": 500639 }
],
"totalHits": "32,870,234",
"maxHits": "2,119,767",
"maxHour": 12,
"minHits": "553,821",
"minHour": 3 }
{ "date": "20120928",
"hours": [
{ "hour": 0, "hits": 1235923 },
{ "hour": 1, "hits": 654335 },
{ "hour": 2, "hits": 1103849 },
{ "hour": 3, "hits": 512863 },
{ "hour": 4, "hits": 488506 }
],
"totalHits": "32,870,234",
"maxHits": "2,119,767",
"maxHour": 12,
"minHits": "553,821",
"minHour": 3 }
我最終想要做的就是創建多個雷達圖,每天一個,描繪每個小時命中。但即使進入「小時」陣列,我也遇到了麻煩。我可以,例如,讓所有的日期列表,像這樣:
d3.select("body")
.append("ul")
.selectAll("li")
.data(data)
.enter()
.append("li")
.text(function (d,i) {
return d.date;
});
但我不能在任何多個嵌套得到。有人能幫助我指出正確的方向嗎?
另外這個要點我爲自己理解嵌套:http://bl.ocks.org/d/4018151/ – PhoebeB