我正在尝试使用 d3.js 在表中显示关联数组的数据,但我无法获取表中的各个值。
这是我的数组的一部分:
var twitterDays =
[
{
0:
{
0: 0,
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0,
11: 0,
12: 0,
13: 0,
14: 0,
15: 0,
16: 0,
17: 0,
18: 0,
19: 0,
20: 0,
21: 0,
22: 0,
23: 0,
"total": 0
},
"day": "monday"
},
{
1:
{
0: 0,
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0,
11: 0,
12: 0,
13: 0,
14: 0,
15: 0,
16: 0,
17: 0,
18: 0,
19: 0,
20: 0,
21: 0,
22: 0,
23: 0,
"total": 0
},
"day": "tueday"
}, etc etc
使用 d3.js,我正在向不同的键添加值。
这就是我制作桌子的方式:
var table = d3.select("#datavis").append("table").attr("class", "twitterTable");
var tbody = table.append("tbody");
var rows = tbody.selectAll("tr")
.data(twitterDays)
.enter()
.append("tr").attr("class", function(d) { return d["day"] });
var monday = tbody.select(".monday")
.data(d3.values(twitterDays[0][0]))
.enter()
.append("td")
.text(d3.values(twitterDays[0][0]));
这是我认为需要改变的部分:.text(d3.values(twitterDays[0][0]));
问题是我想要制作的“td”中的单个值(每个1),但是我得到每个“td”中所有值的所有值..
这就是我得到的:
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
<td>39,25,20,11,9,8,2,3,9,36,36,48,57,58,51,50,75,63,67,58,62,74,67,64,992</td>
etc etc
我想要这样:
<td>39</td>
<td>25</td>
<td>20</td>
<td>11</td>
<td>9</td>
<td>8</td>
<td>2</td>
etc etc