[英]changing svg circles to image
我是d3js的新手,目前正在我堅持的一個項目中工作。 這是我的語法
var node = svg.selectAll(".node")
.data(data.nodes)
.enter()
//.append("circle")
//.attr("r",5)
.append("img")
.attr("class", function(d) { return "flag flag-" + d.code; })
node.style('left', d => d.x + "px")
.style('top', d => d.y + "px");
/*
node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
*/
基本上,我想做的是將圓圈(我已經將其注釋掉)更改為圖像。 您能幫我弄清楚我所缺少的嗎?
您可以使用以下代碼附加圖像並相應地調整“ x”和“ y”坐標:
var node = svg.selectAll(".node")
.data(data.nodes)
.enter()
.append('image')
.attr('xlink:href', 'http://www.charbase.com/images/glyph/9899')
.attr('width', '50px')
.attr('height', '50px')
.attr("class", function(d) { return "flag flag-" + d.code; });
force.on("tick", function() {
.
.
// node.style('left', d => d.x + "px")
// .style('top', d => d.y + "px");
node.attr("x", function(d) { return d.x - 25; })
.attr("y", function(d) { return d.y - 25; });
.
.
});
我已經在https://jsfiddle.net/o81reo7a/中更新了您的代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.