我的目标是使用 d3 将图像添加到现有圆圈中。圆圈将呈现并与 mouseover 方法交互,但仅当我使用"fill",时"color",而不是更复杂的东西,如.append("image").
g.append("circle")
.attr("class", "logo")
.attr("cx", 700)
.attr("cy", 300)
.attr("r", 10)
.attr("fill", "black") // this code works OK
.attr("stroke", "white") // displays small black dot
.attr("stroke-width", 0.25)
.on("mouseover", function(){ // when I use .style("fill", "red") here, it works
d3.select(this)
.append("svg:image")
.attr("xlink:href", "/assets/images/logo.jpeg")
.attr("cx", 700)
.attr("cy", 300)
.attr("height", 10)
.attr("width", 10);
});
鼠标悬停后图像不显示。使用 Ruby on Rails 应用程序,我的图像“logo.jpeg”存储在assets/images/ directory. 让我的标志在圈子内显示有什么帮助吗?谢谢。