【发布时间】:2014-08-15 07:43:39
【问题描述】:
我有以下 JSON
{
"users":
{
"gender":
{
"tot":
[
{"label":"female", "value":6038},
{"label":"male", "value":45228},
{"label":"unknown", "value":32932}
]
}
}
}
我可以使用d3.json() 加载文件并通过console.log() 将其可视化,但我无法访问内部值和标签
请考虑以下脚本
d3.json("../data/m5s/sumStats.json", function(data) {
console.log(data)
x.domain(data.map(function(d) {
return d[0].users[0].gender[0].comment[0].label;
}));
});
在第三行返回
Uncaught TypeError: undefined is not a function
【问题讨论】:
-
您的标签访问代码与您的对象定义不匹配。除此之外,x 是在哪里定义的?
-
对象没有可用的
map方法。因此,调用data.map()将产生“TypeError: undefined is not a function”。
标签: javascript json d3.js