score:5

Accepted answer

Some of the examples in the d3 sample library may produce errors in certain browsers when you try to run static files locally. Mike suggests that you run python's simplehttpserver while browsing the samples.

See instructions here: https://github.com/mbostock/d3/wiki

python -m SimpleHTTPServer 8888

score:9

d3.js is a client side JavaScript library so you don't need any servers in the background. To begin use static files. Here is a short example:

index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My first d3.js</title>
    <link href="style.css" rel="stylesheet">
  </head>

  <body>
    <div id="mySVG"></div>
    <script src="http://d3js.org/d3.v2.js"></script>
    <script>
      var svg = d3.select("#mySVG")
        .append("svg")
        .attr("width", 200)
        .attr("height", 200)

      svg.append("text")
        .attr("x", 50)
        .attr("y", 50)
        .attr("class", "text")
        .text("d3.js is awesome")
    </script>
  </body>

and a style.css for styling:

.text {
  fill: blue;
}

Open index.html in the browser and you should see a blue text saying "d3.js is awesome". More helpful tutorials are:

and of course


Related Query