如何运行Mike Bostock的D3示例? [英] How to run Mike Bostock's D3 examples?

查看:192
本文介绍了如何运行Mike Bostock的D3示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图运行Mike Bostock的 See-Through Globe 示例,但是如果您尝试在本地重现它,则对其json文件的引用不正确。

I've been trying to run Mike Bostock's See-Through Globe example, but the references to his json files are incorrect if you try to reproduce it locally.

问题来自这行代码:

d3.json("/mbostock/raw/4090846/world-110m.json", function(error, topo) {
      var land = topojson.feature(topo, topo.objects.land),
          grid = graticule();
});

我按照这个例子:
d3:我们在topojson格式文件中的状态太大了

并尝试将网址更改为这些版本,以便更好地为外部用户引用这些文件;

and tried to change the url to these variations to better reference those files for an external user;

"https://raw.github.com/mbostock/topojson/master/examples/world-110m.json"
"https://render.github.com/mbostock/topojson/master/examples/world-110m.json"
"http://bl.ocks.org/mbostock/raw/4090846/world-110m.json"

但我绝不允许访问。关于如何正确引用json文件的任何想法?

but I'm never allowed access. Any idea on how to correctly reference the json file?

如果他的其他例子也尝试了一些,并且每次遇到同样的问题。有没有其他人成功复制这些例子?

I've tried some if his other examples as well, and have run into the same issue every time. Has anyone else had any success reproducing the examples?

链接到图库示例

链接到github要点

推荐答案

你无法访问远程json文件,因为相同的原始策略。并且您将无法使用file:protocol检索JSON对象。除非您想通过直接嵌入JSON来对代码进行手术,否则您将不得不运行本地服务器。

You can't access the remote json files because of same origin policy. And you won't be able to retrieve a JSON object using the file: protocol. Unless you want to perform surgery on the code by embedding the JSON directly, you're going to have to run a local server.

运行本地Web的简便方法服务器执行:

An easy way to run a local web server is execute:

python -m SimpleHTTPServer 8888 &

来自您网站的root目录,然后通过 http访问它:// localhost:8888

from the "root" directory of your site and then access it via http://localhost:8888

这篇关于如何运行Mike Bostock的D3示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆