Anton Anton - 3 months ago 15
JSON Question

Problems during getting data from external JSON in D3.js

I'm trying to load some data from the external JSON file to put them into the tooltip, but something is going wrong and I can't figure it out. My JSON looks like this:

{
"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"
}
]
}


It's the part of my code where I'm trying to get the data:

d3.json("test_json.json", function(error, data) {
dataViz(data.results);
});


Here is the full code on jsfiddle: http://jsfiddle.net/anton9ov/v1rz2vfu/

Answer

Use the full address for the 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);
});