我试图从外部JSON文件中加载一些数据以将它们放入工具提示中,但出现了问题,我无法弄明白。我的JSON看起来像这样:
{
"results": [
{
"name": "First Candidate",
"result": 52,
"victory": "winner",
"region": "First region",
"constituencyName": "First constituency",
"constituencyNumber": 1,
"partyName": "Ruling party",
"partyShort": "PR",
"partyStatus": "Right"
},
{
"name": "Second Candidate",
"result": 48,
"victory": "looser",
"region": "First region",
"constituencyName": "First constituency",
"constituencyNumber": 1,
"partyName": "Opposition party",
"partyShort": "OP",
"partyStatus": "Left"
}
]
}
这是我的代码中我试图获取数据的部分:
d3.json("test_json.json", function(error, data) {
dataViz(data.results);
});
以下是jsfiddle的完整代码:http://jsfiddle.net/anton9ov/v1rz2vfu/
答案 0 :(得分:1)
使用json的完整地址:http://jsfiddle.net/thatOneGuy/v1rz2vfu/15/
d3.json("https://dl.dropboxusercontent.com/u/23920803/infographics/2016/2016.08.29_elections_results/my_files/test_json/test_json.json", function(error, data) {
dataViz(data.results);
});