score:2

Accepted answer

make sure that your files are being served properly by an http server. the main question here is whether or not you're pasting the json directly into the index.html that you're creating or if you're using a separate json file.

d3.json makes an ajax call to load the json file. in order to make this json request you must have an http server serving the directory that contains the separate json file. this could very well be why when you change directories (perhaps to a directory that is being served by some server) the expected chart appears. if instead you replace the d3.json call with a reference to the json in an inline manner, you do not need a server. instead you should be able to view the example statically from your file system with your browser no matter the directory it is in.

the reason for needing a server is due to the same origin policy that is described in w3c standards. you can find out a simple solution in this s.o. post: d3 bar graph example not working locally. it offers two solutions, to either spawn a http server for the directories that the files are being served or to modify the same origin policies in your browser. i recommend the server approach due to safety standards.


Related Query