D3文件不能在Chrome中使用,但可以在Firefox中使用

编程入门 行业动态 更新时间:2024-10-24 19:29:02
本文介绍了D3文件不能在Chrome中使用,但可以在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中使用

本文发布于:2023-11-09 22:55:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573658.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能在   文件   Chrome   Firefox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!