我是D3.js的新手.我正在阅读Mike Dewar的D3入门.我尝试了书中的第一个例子,它不起作用.我一直在撕扯我的声音.这里的代码出了什么问题?
在该<head>部分:
<script src="http://mbostock.github.com/d3/d3.js"></script>
<script>
function draw(data) {
"use strict";
d3.select("body")
.append("ul")
.selectAll("li")
.data(data)
.enter()
.append("li")
.text(function (d) {
return d.name + ": " + d.status;
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
在<body>:
<script>
d3.json("flare.json", draw);
</script>
Run Code Online (Sandbox Code Playgroud)
和JSON文件:
[
{
"status": ["GOOD SERVICE"],
"name": ["123"],
"url": [null],
"text": ["..."],
"plannedworkheadline": [null],
"Time": [" 7:35AM"],
"Date": ["12/15/2011"]
}
]
Run Code Online (Sandbox Code Playgroud)
如果您使用的是Chrome,则可能会因为跨域安全限制而无法正常打开文件.尝试Firefox,看看是否是这种情况(它可能会让你正确加载文件).
如果这是问题,您将需要安装本地Web服务器,如WAMP(如果您正在运行Windows)或按照维基页面上的说明操作:https://github.com/mbostock/d3/wiki
祝好运