admin管理员组

文章数量:1295783

I have this in my index.html file but it does not show the paragraph that I want to add with D3

<!DOCTYPE html>
<html>
  <head>
    <title> D3 page template </title>
    <script type="text/javascript" src = "d3/d3.v3.js"></script> 
  </head>

  <body>
    <script type="text/javascript">
        d3.select("body").append("p").text("new paragraph!");
    </script>
  </body>
</html>

The path to where I am referencing D3.js should be correct because if I do an inspect element in the browser I can click on the D3 link and it takes me to its source code.

I have this in my index.html file but it does not show the paragraph that I want to add with D3

<!DOCTYPE html>
<html>
  <head>
    <title> D3 page template </title>
    <script type="text/javascript" src = "d3/d3.v3.js"></script> 
  </head>

  <body>
    <script type="text/javascript">
        d3.select("body").append("p").text("new paragraph!");
    </script>
  </body>
</html>

The path to where I am referencing D3.js should be correct because if I do an inspect element in the browser I can click on the D3 link and it takes me to its source code.

Share Improve this question edited May 21, 2013 at 13:19 asked May 21, 2013 at 13:06 user1899082user1899082 7
  • 2 Use d3js.org/d3.v3.min.js in src for d3 – Prasath K Commented May 21, 2013 at 13:14
  • also attached the picture of the error I get. – user1899082 Commented May 21, 2013 at 13:19
  • @PrasathK : hmm yeah it worked with directly referencing it from the web site but WHY the local one is not working? – user1899082 Commented May 21, 2013 at 13:21
  • You might have referenced wrongly – Prasath K Commented May 21, 2013 at 13:21
  • but when I click on it in debugger, it does go to its source code. – user1899082 Commented May 21, 2013 at 13:22
 |  Show 2 more comments

3 Answers 3

Reset to default 16

You are missing the character set in your HTML page. Add something like this:

<meta charset="utf-8">

The un-minified source of D3 includes the actual symbol for pi, which confuses the browser if the character set is not defined.

I am going to assume that you are testing this out without a web server. If so, then your URL will read file://.... not http://..

With this, the Javascript request will go to file:///.../D3/d3/d3.v3.js which won't have the proper response header set, such as charset and MIME.

You can always get it from a CDN to avoid this problem:

<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>

Was having similar issue. My problem was my script file was loading before it could load the d3js library. Just adding defer fixed the issue.

<script src="app.js" defer></script>

本文标签: javascriptSimplest D3js example not workingStack Overflow