D3样品在微软堆栈 [英] D3 samples in a Microsoft Stack

查看:254
本文介绍了D3样品在微软堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在努力熟悉D3( http://d3js.org/ ),特别是在样品如 http://bl.ocks.org/mbostock/3306362 并的 http://bl.ocks.org/mbostock/2206590 。似乎所有这些样品使用本地文件IO加载地理位置信息。下面code片段是常见的:

We're trying to get familiar with D3 (http://d3js.org/), in particular samples such as http://bl.ocks.org/mbostock/3306362 and http://bl.ocks.org/mbostock/2206590. It seems all these samples use local file IO to load geolocation info. The following code snippets are common:

queue()
.defer(d3.json, "/mbostock/raw/4090846/us.json")
.defer(d3.tsv, "unemployment.tsv")
.await(ready)

而其他样品经常使用这个签名来加载数据:

while other samples often use this signature to load data:

d3.json("someJSONFile.json", function(error, uk) {
console.log(uk);
});

我们已经创建了几个本地HTML文件来测试样品,但我们遇到了安全问题。这是显而易见的脚本访问本地文件,这实在是让我们在Microsoft堆栈问题(苹果或Linux是不是在这个时间选择,虽然我们已经尝试过Chrome浏览器,没有成功)。我们怎样才能使HTML文件或重构脚本可以访问本地文件?

We've created several local html files to test out the samples, but we're running into security issues. It's apparent the script is accessing a local file, which is really giving us problems in a Microsoft stack (Apple or Linux isn't an option at this time, though we have tried Chrome, with no success). How can we enable the html file or refactor the script to have access to the local files?

推荐答案

您需要通过Web服务器来托管文件,因为Web浏览器限制哪些类型的文件可以在本地进行访问。最简单的方式做到这一点在Windows机器上:

You need to host the files through a web server since web browsers restrict what types of files can be accessed locally. The simplest way to do this on a windows machine:


  1. 蟒蛇

导航持有与的cmd.exe 你的榜样的目录。按住Shift键,右键单击该文件夹的例子,选择此处打开命令窗口是做最简单的方法。

Navigate to the directory holding your example with cmd.exe. Holding down shift, right clicking on the folder with the example and selecting Open Command Window Here is the easiest way to do this.

在命令提示符下,输入蟒蛇-m SimpleHTTPServer 8000 蟒蛇-m http.server 8000 ,在新版本启动Web服务器。

On the command prompt, enter python -m SimpleHTTPServer 8000, or python -m http.server 8000, on newer versions to start a web server.

打开网页浏览器(我真的建议镀铬的开发工具是遥遥领先的FF和IE),转到 127.0.0.1:8000 。本示例应显示出来。

Open a web browser (I would really suggest chrome, the dev tools are way ahead of ff and ie), go to 127.0.0.1:8000. The example should show up.

这篇关于D3样品在微软堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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