use*_*833 3 javascript svg d3.js force-layout
我是D3JS的新手,我需要为每个节点创建包含图像或圆形的力布局.这意味着,动态添加A Image节点或Circle节点.这可能吗?,如果有任何例子请回答
好吧,如果你只是想在圆圈中间有一个图像,试试这个:
/* Create nodes */
var node = vis.selectAll("g.node")
.data(json.nodes) // get the data how you want
.enter().append("svg:g")
.call(node_drag);
/* append circle to node */
node.append("svg:circle")
.attr("cursor","pointer")
.style("fill","#c6dbef")
.attr("r", "10px"})
/* append image to node */
node.append("image")
.attr("xlink:href", "https://github.com/favicon.ico")
.attr("x", -8)
.attr("y", -8)
.attr("width", 16)
.attr("height", 16);
Run Code Online (Sandbox Code Playgroud)
你也可以附加一个标题,一些文字...查看该文件的selection.append(name)更多信息.