0
我知道JSON不能在Chrome
本地加載,因爲很多其他問題已經討論過了。我試圖重新創建這個:https://romsson.github.io/dragit/example/nations.html用d3加載本地JSON文件
我試圖實現硬編碼json的解決方案。
工作代碼:
d3.json("https://rawgit.com/romsson/dragit/master/data/nations.json", function(nations) {
....
我試圖加載nations.json
本地:
var nations = [{"name":"Angola","region":"Sub-Saharan Africa","income":[[2006,12127071],[2007,12420476],[2008,12707546]],
"lifeExpectancy":[[2006,46.02],[2007,46.54],[2008,47.06]]},
{"name":"Benin","region":"Sub-Saharan Africa","income":[[2006,7862944],[2007,8078314],[2008,8294941]],
"lifeExpectancy":[[2006,60.6],[2007,61.03],[2008,61.47]]}]
d3.json(nations, function(nations) {
....
我得到的錯誤:
Failed to load resource: the server responded with a status of 404 (Not Found)
'd3.json()'需要一個URL,而不是一個對象。 – SLaks
只是將d3.json(國家,...)內容更改爲函數並傳遞國家對象。 – karthick
@ karthick只是變成'功能(國家){'?我對javascript和d3非常陌生,但是這並沒有起到作用 – user2242044