问题
I'm completely new to JavaScript and D3.js. I have done some work in recent days, like making appropriate json object for the graph, and wanted to know how to get this example running in particular. Any direction to appropriate links would be great, though I would prefer to get an answer in the form of any missing tags or any details I need to take care of.
Note: I have to run it locally, not on server-client model.
Update: I have done it a lot of times what Bill answered, it didn't work. So I tried again and I opened the console in browser to check for any errors. Got this:
Failed to load resource: file://d3js.org/d3.v3.min.js
net::ERR_FILE_NOT_FOUND
index.html:23 Uncaught ReferenceError: d3 is not defined
回答1:
The point is that you cannot access files on your computer from javascript using file://
(think that people could access all your file...).
So you have to use <script src="address/d3.js"></script>
here, address
correspond to the address of your server (http://domain.com
or http://localhost
) or the relative path.
For example, you can download d3.js next to your html file (same folder) and just type <script src="d3.js"></script>
Hope this helps
回答2:
You can do the following:
- Go to https://gist.github.com/mbostock/4062045
- Click on the Raw button next to index.html
- Copy everything and paste it into a file on your computer called index.html
- Go back and click on the Raw button next to the .json file
- Copy everything and paste it into a file on your computer called miserables.json (make sure this file is in the same folder as index.html)
- Double click on index.html, it should open in your browser
来源:https://stackoverflow.com/questions/35859699/d3-js-starternoob-how-to-get-a-d3-example-from-bl-ocks-org-mbostock-working