0

I'm trying to understand d3 via this tutorial So, I've downloaded script, named it d3.js and put it in the same directory with index.html Here is code of index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>D3 Test</title>
        <script type="text/javascript" src="d3.js"></script>
        <style type="text/css"></style>
    </head>
    <body>
        <script type="text/javascript">
            d3.select("body").append("p").text("New paragraph!");
        </script>
    </body>
</html> 

However, when I load page, I don't see a new paragraph? What is wrong?

Sergey Scopin
  • 2,217
  • 9
  • 39
  • 67

1 Answers1

1

The snippet below is how jsFiddle sets up a working, d3-enabled page. I am not sure what exactly causes your problem, but maybe you could try copying the header.

I generally recommend including libs, like d3, via a CDN (e.g. cloudflare, or d3's own server, as in the fiddle), since the cached version can then be used across site domains (due to its absolute link), without being downloaded every time.

<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title> - jsFiddle demo</title>

    <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script><style    type="text/css"></style>

    <link rel="stylesheet" type="text/css" href="/css/result-light.css">

    <script type="text/javascript">//<![CDATA[ 
        window.onload=function(){ 
            d3.select("body").append("p").text("New paragraph!");
        }//]]>
    </script>
 </head><body></body></html>

You can keep your script tag at the bottom of the body though.

Community
  • 1
  • 1
craPkit
  • 615
  • 1
  • 7
  • 20