【发布时间】:2015-05-03 13:57:24
【问题描述】:
我正在处理一个团队项目,并且 d3 地图可以在除我之外的其他所有人的计算机上正确渲染。这是我的地图代码 sn-p:
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 上中断,它说在 undefined 上没有方法“功能”。这是我的 geoJson sn-p:
{
"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 ], ...
如您所见...我有一个名为“功能”的属性。
另外,我的地图适用于 Firefox,但不适用于 chrome。知道发生了什么吗?
回调中传递的错误信息:
SyntaxError: Unexpected token { {stack: (...), message: "Unexpected 令牌{"}
【问题讨论】:
-
也许你应该先从你的ajax请求中检查
error? -
您提供文件的方法是什么?您是在访问 URL:“file:///myd3.html”还是在运行本地服务器并使用“localhost.../myd3.html”
-
您可以将文件上传到某个地方,以便不同的人可以使用不同的浏览器进行测试。以防万一文件准备好发布 =)