The way I have seen to do this is to queue the functions using queue.js, as described in the book "D3.js in Action" by Elijah Meeks. Sample code for chapter 6 is on the Manning website, see listing 6.7. (and buy the book, it's quite good) here's the basic structure slightly adapted to your use case:

   <script src=""></script>
   .defer(d3.csv, "csvVertices.csv")
   .defer(d3.csv, "csvEdges.csv")
   .await(function(error, file1, file2) {createForceLayout(file1, file2);});
   function createForceLayout(nodes, edges) {
     var nodeHash = {};
     for (x in nodes) {
       nodeHash[nodes[x].id] = nodes[x];
     for (x in edges) {
       edges[x].weight = 1; //you have no weight
       edges[x].source = nodeHash[edges[x].source];
       edges[x].target = nodeHash[edges[x].target];
     force = d3.layout.force()

Related Query

More Query from same tag