D3文件不能在Chrome中使用,但可以在Firefox中使用 [英] d3 file not working in chrome but works in firefox
问题描述
我正在一个团队项目上,并且d3贴图可以在我的其他人的计算机上正确渲染.这是我的地图代码段:
I'm working on a team project and the d3 map is rendering correctly on everyone else's computer but mine. Here's my map code snippet:
var g = svg.append("g");
// as written, the function(error, us) callback won't fire until the d3.json finishes
d3.json("json/usa_map.json", function(error, us) {
g.selectAll("path")
.data(us.features)
.enter()
它在us.features
处中断,并且说未定义方法没有功能".这是我的geoJson片段:
It breaks on us.features
and it says there is no method "features" on undefined. Here is my geoJson snippet:
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "GEO_ID": "0400000US04", "STATE": "04", "NAME": "Arizona", "LSAD": "", "CENSUSAREA": 113594.084000 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -112.538593, 37.000674 ], [ -112.534545, 37.000684 ], [ -112.368946, 37.001125 ], [ -112.357690, 37.001025 ], [ -111.412784, 37.001478 ], [ -111.405869, 37.001481 ], [ -111.405517, 37.001497 ], [ -111.189888, 37.000959 ], ...
因此,您可以看到...我有一个称为功能"的属性.
So as you can see... I have a property called "features".
此外,我的地图在Firefox上有效,但在chrome上无效.知道发生了什么吗?
Also, my map works on firefox but not chrome. Any idea what is going on?
在回调中传递的错误消息:
The error message that gets passed in the callback:
SyntaxError:意外令牌{{堆栈:(...),消息:意外 令牌{}
SyntaxError: Unexpected token { {stack: (...), message: "Unexpected token {"}
推荐答案
这意味着在这种情况下,服务器对json/usa_map.json
的响应不能被解析为有效的JSON
.我无法推测原因,但是如果您在Chrome开发工具的网络"标签中查看响应,则很明显.
This means the server's response to json/usa_map.json
in this case cannot be parsed as valid JSON
. I cannot speculate why, but if you look at the response in the Chrome Dev Tools' Network tab it will probably be obvious.
这篇关于D3文件不能在Chrome中使用,但可以在Firefox中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!