0
我正在开发一个团队项目,并且d3地图在其他人的计算机上正确渲染,但我的是。这里是我的地图代码片段:d3文件不能在Chrome中工作,但在Firefox中工作
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片段:
{
"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上工作,但不是铬。任何想法是怎么回事?
是被在回调中传递的错误信息:
SyntaxError: Unexpected token { {stack: (...), message: "Unexpected token {"}
也许你应该首先检查你的ajax请求中的'error'? – Oleg
你的文件服务方式是什么?您是否正在访问URL:“file:///myd3.html”,或者您正在运行本地服务器并使用“http://localhost.../myd3.html” – cmonkey
您可以将文件上传到不同的人用不同的浏览器测试。以防文件准备好发布=) – kwoxer