user2242044 user2242044 -3 years ago 60
Javascript Question

loading a local JSON file with d3

I know JSON can't load locally in

as many other questions have discussed. I am trying to recreate this:

I have tried to implement the solution of hardcoding the json.

Working code:

d3.json("", function(nations) {


My attempt to load

var nations = [{"name":"Angola","region":"Sub-Saharan Africa","income":[[2006,12127071],[2007,12420476],[2008,12707546]],
{"name":"Benin","region":"Sub-Saharan Africa","income":[[2006,7862944],[2007,8078314],[2008,8294941]],

d3.json(nations, function(nations) {


I get the error:

Failed to load resource: the server responded with a status of 404 (Not Found)

Answer Source

d3.json is used to load data from url not an object present in the page. So if you have an object already in the page just pass it to the required function.


function draw(nationsObj){
    // A bisector since many nation's data is sparsely-defined.
       var bisect = d3.bisector(function(d) { return d[0]; });


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download