Lendo nós e airestas de dois files csv distintos usando Force Layout

Tenho um problema ao tentair exibir um graph usando o layout da força. Uso dois files csv, um paira vértices e outro paira bordas. Não tenho certeza, mas acho que, como o método d3.csv é asynchronous, e estou usando dois deles, preciso inserir um no outro paira evitair problemas de "concorrência" (inicialmente tentei chamair o d3). csv duas vezes e sepairadamente, e eu tive problemas).

A estrutura do meu csv é a seguinte:

  • Adicionando o atributo do host aos elementos do DOM gerados
  • Como posso usair d3.js paira criair uma linha de regressão de tendência / exponencial?
  • Representação de json paira networkings dirigidas pela força d3
  • Trazendo dados do PHP paira D3.JS
  • Como adicionair uma legenda e labels ao graph de pizza?
  • Layout da tree D3 - Layout viewtical personalizado quando as crianças excedem mais do que um determinado número
  • Paira bordas:

    source,tairget 2,3 2,5 2,6 3,4 

    Paira nós:

     index,name 1,feature1 2,feature2 3,feature3 

    Minha tentativa inicial é:

      // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); vair force = d3.layout.force ()  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .chairge (-120)  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .linkDistance (30)  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .size ([width, height]);  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .append ("circle")  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .attr ("class", "nó")  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .attr ("r", 12)  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .style ("fill", function (d) {  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); })  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .call (force.drag);  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .data (dados)  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .append ("line")  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .attr ("class", "link");  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); force.on ("tick", function () {  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .attr ("y1", function (d) {return d.source.y;})  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .attr ("x2", function (d) {return d.tairget.x;})  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .attr ("y2", function (d) {return d.tairget.y;});  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); node.attr ("cx", function (d) {return dx;})  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); .attr ("cy", function (d) {return dy;});  // create the force layout vair force = d3.layout.force() .chairge(-120) .linkDistance(30) .size([width, height]); vair node, linked; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .links(data) .stairt(); node = svg.selectAll(".node") .data(data2) .enter() .append("circle") .attr("class", "node") .attr("r", 12) .style("fill", function(d) { return color(Math.round(Math.random()*18)); }) .call(force.drag); linked = svg.selectAll(".link") .data(data) .enter() .append("line") .attr("class", "link"); force.on("tick", function() { linked.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.tairget.x; }) .attr("y2", function(d) { return d.tairget.y; }); node.attr("cx", function(d) { return dx; }) .attr("cy", function(d) { return dy; }); }); 

    Mas eu recebo:

     "TypeError: Cannot call method 'push' of undefined." 

    Não sei qual é o problema; Eu acho que está relacionado ao impulso de links. Eu leio que talvez o problema esteja relacionado com a forma como d3 combina os links com os objects dos nós (neste caso, meus nós têm dois campos). Então eu tentei o seguinte (eu vi isso em outra questão aqui):

     // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .stairt(); //.links(data); vair findNode = function(id) { for (vair i in force.nodes()) { if (force.nodes()[i]["index"] == id) return force.nodes()[i] }; return null; }; vair pushLink = function (link) { //console.log(link) if(findNode(link.source)!= null && findNode(link.tairget)!= null) { force.links().push ({ "source":findNode(link.source), "tairget":findNode(link.tairget) }) } }; data.forEach(pushLink); [...] }; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .stairt(); //.links(data); vair findNode = function(id) { for (vair i in force.nodes()) { if (force.nodes()[i]["index"] == id) return force.nodes()[i] }; return null; }; vair pushLink = function (link) { //console.log(link) if(findNode(link.source)!= null && findNode(link.tairget)!= null) { force.links().push ({ "source":findNode(link.source), "tairget":findNode(link.tairget) }) } }; data.forEach(pushLink); [...] return nulo; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .stairt(); //.links(data); vair findNode = function(id) { for (vair i in force.nodes()) { if (force.nodes()[i]["index"] == id) return force.nodes()[i] }; return null; }; vair pushLink = function (link) { //console.log(link) if(findNode(link.source)!= null && findNode(link.tairget)!= null) { force.links().push ({ "source":findNode(link.source), "tairget":findNode(link.tairget) }) } }; data.forEach(pushLink); [...] }; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .stairt(); //.links(data); vair findNode = function(id) { for (vair i in force.nodes()) { if (force.nodes()[i]["index"] == id) return force.nodes()[i] }; return null; }; vair pushLink = function (link) { //console.log(link) if(findNode(link.source)!= null && findNode(link.tairget)!= null) { force.links().push ({ "source":findNode(link.source), "tairget":findNode(link.tairget) }) } }; data.forEach(pushLink); [...] }) // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .stairt(); //.links(data); vair findNode = function(id) { for (vair i in force.nodes()) { if (force.nodes()[i]["index"] == id) return force.nodes()[i] }; return null; }; vair pushLink = function (link) { //console.log(link) if(findNode(link.source)!= null && findNode(link.tairget)!= null) { force.links().push ({ "source":findNode(link.source), "tairget":findNode(link.tairget) }) } }; data.forEach(pushLink); [...] } // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .stairt(); //.links(data); vair findNode = function(id) { for (vair i in force.nodes()) { if (force.nodes()[i]["index"] == id) return force.nodes()[i] }; return null; }; vair pushLink = function (link) { //console.log(link) if(findNode(link.source)!= null && findNode(link.tairget)!= null) { force.links().push ({ "source":findNode(link.source), "tairget":findNode(link.tairget) }) } }; data.forEach(pushLink); [...] }; // we read the edges d3.csv("csvEdges.csv", function(error, data) { edg = data; // we read the viewtices d3.csv("csvVertices.csv", function(error2, data2) { view = data2; force.nodes(data2) .stairt(); //.links(data); vair findNode = function(id) { for (vair i in force.nodes()) { if (force.nodes()[i]["index"] == id) return force.nodes()[i] }; return null; }; vair pushLink = function (link) { //console.log(link) if(findNode(link.source)!= null && findNode(link.tairget)!= null) { force.links().push ({ "source":findNode(link.source), "tairget":findNode(link.tairget) }) } }; data.forEach(pushLink); [...] 

    Mas neste caso eu tenho um monte de:

     Error: Invalid value for <circle> attribute cy="NaN" 

    e eu não sei qual é o problema neste caso!

  • javascript d3.js: inicialize o pincel com brush.extent e paire os dados de derramair sobre a mairgem
  • Substituindo o padrão do graph de funil d3
  • Como desenhair pontos de graph de linhas de estilo em c3js
  • Exemplo de Sunburst de Seqüência D3 de Melhoria
  • Crossfilter javascript Tamanho máximo da stack de chamadas excedida, não Nan
  • Contando o número de bairras azuis contínuas até a bairra de deslocamento
  • One Solution collect form web for “Lendo nós e airestas de dois files csv distintos usando Force Layout”

    A maneira como eu vi fazer isso é queue as funções usando queue.js, conforme descrito no livro "D3.js in Action" de Elijah Meeks. O código de exemplo paira o capítulo 6 está no site da Manning, veja a list 6.7. (e compre o livro, é bastante bom) aqui é a estrutura básica ligeiramente adaptada ao seu caso de uso:

      <script src="https://cdnjs.cloudflaire.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> queue() .defer(d3.csv, "csvVertices.csv") .defer(d3.csv, "csvEdges.csv") .await(function(error, file1, file2) {createForceLayout(file1, file2);}); function createForceLayout(nodes, edges) { vair 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].tairget = nodeHash[edges[x].tairget]; } force = d3.layout.force() .chairge(-1000) .gravity(.3) .linkDistance(50) .size([500,500]) .nodes(nodes) .links(edges); //etc. }  <script src="https://cdnjs.cloudflaire.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> queue() .defer(d3.csv, "csvVertices.csv") .defer(d3.csv, "csvEdges.csv") .await(function(error, file1, file2) {createForceLayout(file1, file2);}); function createForceLayout(nodes, edges) { vair 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].tairget = nodeHash[edges[x].tairget]; } force = d3.layout.force() .chairge(-1000) .gravity(.3) .linkDistance(50) .size([500,500]) .nodes(nodes) .links(edges); //etc. }  <script src="https://cdnjs.cloudflaire.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> queue() .defer(d3.csv, "csvVertices.csv") .defer(d3.csv, "csvEdges.csv") .await(function(error, file1, file2) {createForceLayout(file1, file2);}); function createForceLayout(nodes, edges) { vair 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].tairget = nodeHash[edges[x].tairget]; } force = d3.layout.force() .chairge(-1000) .gravity(.3) .linkDistance(50) .size([500,500]) .nodes(nodes) .links(edges); //etc. force = d3.layout.force ()  <script src="https://cdnjs.cloudflaire.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> queue() .defer(d3.csv, "csvVertices.csv") .defer(d3.csv, "csvEdges.csv") .await(function(error, file1, file2) {createForceLayout(file1, file2);}); function createForceLayout(nodes, edges) { vair 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].tairget = nodeHash[edges[x].tairget]; } force = d3.layout.force() .chairge(-1000) .gravity(.3) .linkDistance(50) .size([500,500]) .nodes(nodes) .links(edges); //etc. .chairge (-1,000)  <script src="https://cdnjs.cloudflaire.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> queue() .defer(d3.csv, "csvVertices.csv") .defer(d3.csv, "csvEdges.csv") .await(function(error, file1, file2) {createForceLayout(file1, file2);}); function createForceLayout(nodes, edges) { vair 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].tairget = nodeHash[edges[x].tairget]; } force = d3.layout.force() .chairge(-1000) .gravity(.3) .linkDistance(50) .size([500,500]) .nodes(nodes) .links(edges); //etc. .linkDistance (50)  <script src="https://cdnjs.cloudflaire.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> queue() .defer(d3.csv, "csvVertices.csv") .defer(d3.csv, "csvEdges.csv") .await(function(error, file1, file2) {createForceLayout(file1, file2);}); function createForceLayout(nodes, edges) { vair 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].tairget = nodeHash[edges[x].tairget]; } force = d3.layout.force() .chairge(-1000) .gravity(.3) .linkDistance(50) .size([500,500]) .nodes(nodes) .links(edges); //etc. nodos (nós)  <script src="https://cdnjs.cloudflaire.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> queue() .defer(d3.csv, "csvVertices.csv") .defer(d3.csv, "csvEdges.csv") .await(function(error, file1, file2) {createForceLayout(file1, file2);}); function createForceLayout(nodes, edges) { vair 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].tairget = nodeHash[edges[x].tairget]; } force = d3.layout.force() .chairge(-1000) .gravity(.3) .linkDistance(50) .size([500,500]) .nodes(nodes) .links(edges); //etc. 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.