非常简单的教程示例D3.js不工作 [英] Very simple tutorial example of D3.js not working

查看:118
本文介绍了非常简单的教程示例D3.js不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是D3.js的新人。我正在阅读Mike Dewar的 D3入门。我试着在书中的第一个例子,它不工作。我一直在撕裂我听到这个。

I'm kind of new to D3.js. I'm reading Getting Started with D3 by Mike Dewar. I tried the very first example in the book, and it doesn't work. I've been tearing my hear out over this. What is wrong with my code here?

< 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>

< body>

<script>

    d3.json("flare.json", draw);

</script>

和JSON文件:

[
{
    "status": ["GOOD SERVICE"],
    "name": ["123"],
    "url": [null],
    "text": ["..."],
    "plannedworkheadline": [null],
    "Time": [" 7:35AM"],
    "Date": ["12/15/2011"]
}
]


推荐答案

如果您使用的是Chrome,则可能会由于跨域安全限制而无法正常打开文件。尝试Firefox查看是否是这种情况(它可能会让你正确加载文件)。

If you're using Chrome, it may prevent you from opening the file properly because of cross domain security restrictions. Try Firefox to see if that's the case (it will probably let you load the file correctly).

如果这是问题,您将需要安装一个本地Web服务器,如WAMP(如果你运行Windows)或按照wiki页面上的说明: a href =https://github.com/mbostock/d3/wiki =noreferrer> https://github.com/mbostock/d3/wiki

If that is the problem, you will want to install a local web server like WAMP (if you're running Windows) or follow instructions on the wiki page here: https://github.com/mbostock/d3/wiki

祝你好运

这篇关于非常简单的教程示例D3.js不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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