Lyn*_*arl 4 javascript image append d3.js
附加图像我使用此代码
node.append("image")
.attr("xlink:href", function(d) { return d.img; })
.attr("x", -25)
.attr("y", -25)
.attr("width", 50)
.attr("height", 50)
Run Code Online (Sandbox Code Playgroud)
我希望图像是圆的,我试图使用此代码
.attr("style", "border-radius: 30px;");
Run Code Online (Sandbox Code Playgroud)
但它没有用..我也试过这个
<style>
.node image{
border-color: 2px solid orange;
border-radius: 25px;
}
</style>
Run Code Online (Sandbox Code Playgroud)
但无济于事..
你需要使用模式.
<defs>
标记中使用的图像的模式.例如.:
var defs = svg.append("defs").attr("id", "imgdefs")
var catpattern = defs.append("pattern")
.attr("id", "catpattern")
.attr("height", 1)
.attr("width", 1)
.attr("x", "0")
.attr("y", "0")
Run Code Online (Sandbox Code Playgroud)
添加图片:
catpattern.append("image")
.attr("x", -130)
.attr("y", -220)
.attr("height", 640)
.attr("width", 480)
.attr("xlink:href", imgurl)
Run Code Online (Sandbox Code Playgroud)
然后设置填充:
svg.append("circle")
.attr("r", 100)
.attr("cy", 80)
.attr("cx", 120)
.attr("fill", "url(#catpattern)")
Run Code Online (Sandbox Code Playgroud)
JS小提琴示例:http://jsfiddle.net/wcnxywuy/1/
归档时间: |
|
查看次数: |
4534 次 |
最近记录: |