You need to load the file through an asynchronous request with d3.csv. Example code:

d3.csv("dataFile.csv", function(error, data) {
  // do something exciting with data


Your drawing code needs to stay inside csv callback:

d3.csv("testData.csv", function(data){
    // this converts data to number
    data.forEach(function(d) {
        d.x = +d.x;
        d.y = +d.y;

    // rest of drawing code

See another example here:

It's easier to debug if you can post link to working code.

Related Query

More Query from same tag