I'm working through this tutorial
/
I'm trying to just get update nodes working(my data is slightly different).
var updateNodes = function(nodes){
console.log("updateNodes Called");
console.log(nodes);
var node = nodesG.selectAll("circle.node").data(nodes,function(d){
return d.id;
});
node.enter().append("circle").attr("class","node")
.attr("cx",x)
.attr("cy",y)
.attr("r",1000)
.style("fill","steelblue")
.style("stroke","black")
.style("stroke-width",1.0);
node.exit().remove();
}
This does not make any circles appear on the DOM.
nodesG is defined as :
var nodesG = d3.selectAll("g");
and this function is called from
var update = function(){
force.nodes(data.nodes);
updateNodes(data.nodes);
//force.links(curLinksData);
//updateLinks();
//force.start();
}
Why is nothing appearing?
Thanks,
I'm working through this tutorial
http://flowingdata./2012/08/02/how-to-make-an-interactive-network-visualization/
I'm trying to just get update nodes working(my data is slightly different).
var updateNodes = function(nodes){
console.log("updateNodes Called");
console.log(nodes);
var node = nodesG.selectAll("circle.node").data(nodes,function(d){
return d.id;
});
node.enter().append("circle").attr("class","node")
.attr("cx",x)
.attr("cy",y)
.attr("r",1000)
.style("fill","steelblue")
.style("stroke","black")
.style("stroke-width",1.0);
node.exit().remove();
}
This does not make any circles appear on the DOM.
nodesG is defined as :
var nodesG = d3.selectAll("g");
and this function is called from
var update = function(){
force.nodes(data.nodes);
updateNodes(data.nodes);
//force.links(curLinksData);
//updateLinks();
//force.start();
}
Why is nothing appearing?
Thanks,
Share Improve this question asked Apr 7, 2013 at 6:07 praks5432praks5432 7,80232 gold badges93 silver badges158 bronze badges 2- 1 Any way you could put your code on jsFiddle? – summea Commented Apr 7, 2013 at 6:10
-
If nothing is appearing it means that your
.enter()
selection is empty. This could be because your.selectAll()
isn't matching anything or because all the data you pass in is matched with existing data. Did you check those things? – Lars Kotthoff Commented Apr 7, 2013 at 20:14
1 Answer
Reset to default 6The first thing that is not working in your code is that you don't create a svg
element in which you will draw your circle.
So you have to replace
var nodesG = d3.selectAll("g");
by
var nodesG = d3.select('body').append('svg');
Then, you don't define well the attributes x and y of your circles. These attributes, I guess, depend on the property x
and y
of each node. Thus you have to replace the following:
.attr("cx", x)
.attr("cy", y)
by:
.attr("cx", function(d){return d.x})
.attr("cy", function(d){return d.y})
- Finally, you have to call
update()
at the end of your script
Here is a working jsFiddle: http://jsfiddle/chrisJamesC/S6rgv/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744905497a4600228.html
评论列表(0条)