Accepted answer

You are missing a .selectAll('svg') after selecting the div.

var svg ="#chart")
  .selectAll('svg')    // <-- You want to operate on set of SVG elements
    .data(d3.range(2013, 2015))

Working demo:

Also, as a general rule, it is best to run your Javascript code which changes the DOM after the DOM has loaded. I have moved the script tag which ran your code to the bottom of the body tag so that the div#chart has been put into the DOM for'#chart') to find.

Related Query

More Query from same tag