D3.js starter(noob): How to get a D3 example from bl.ocks.org/mbostock working?

五迷三道 提交于 2019-12-13 08:01:24

问题


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:

  1. Go to https://gist.github.com/mbostock/4062045
  2. Click on the Raw button next to index.html
  3. Copy everything and paste it into a file on your computer called index.html
  4. Go back and click on the Raw button next to the .json file
  5. 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)
  6. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!