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:

python -m SimpleHTTPServer 8888


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:


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

    <div id="mySVG"></div>
    <script src=""></script>
      var svg ="#mySVG")
        .attr("width", 200)
        .attr("height", 200)

        .attr("x", 50)
        .attr("y", 50)
        .attr("class", "text")
        .text("d3.js is awesome")

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