2015-05-01 203 views
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 {"}

+1

也許你應該首先檢查你的ajax請求中的'error'? – Oleg

+1

你的文件服務方式是什麼?您是否正在訪問URL:「file:///myd3.html」,或者您正在運行本地服務器並使用「http://localhost.../myd3.html」 – cmonkey

+0

您可以將文件上傳到不同的人用不同的瀏覽器測試。以防文件準備好發佈=) – kwoxer

回答

1

這意味着在這種情況下,服務器對json/usa_map.json反應不能被解析爲有效JSON。我無法推測爲什麼,但如果您在Chrome Dev Tools的「網絡」選項卡中查看響應,它可能會很明顯。

相關問題