jslutzky
jslutzky

Reputation: 419

d3 visualization not appearing

I'm trying to get a very basic d3 visualization working, but all I get is a blank browser window.

Here's my index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://d3js.org/d3.v4.min.js"></script>
    <script src="code.js"></script>
    <title>My Title</title>
  </head>
  <body>
    <div class="container"></div>
  </body>
</html>

Here's my code.js:

console.log("test");

d3.select("body").append("h1").html("Here are some words")

My console prints test. But nothing appears in the browser window. When I inspect element, nothing has been added.

I've tried loading the localhost page via python -m SimpleHTTPServer and via npm install -g http-server plus http-server &.

What's going wrong?

Upvotes: 0

Views: 994

Answers (1)

federico medrano
federico medrano

Reputation: 46

you need to change your HTML code for the following code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <script src="https://d3js.org/d3.v4.min.js"></script>    
    <title>My Title</title>
  </head>
  <body>
       <div class="container"></div>
       <script type="text/javascript" src="code.js"></script>
 </body>
</html>

I just put the line which reference the "code.js" inside the body tags

Upvotes: 3

Related Questions