Here is my JSFiddle.如何樣式化SVG路徑以拍攝圖像?
我只是試圖在弧的中間設置this image。我最好的直覺告訴我要使用.attr(「fill」,「url('somePicture')」),但是對於我來說這並不是一個可行的解決方案。
var width = 700,
height = 600,
tau = 2 * Math.PI
var arc = d3.svg.arc()
.innerRadius(100)
.outerRadius(250)
.startAngle(0)
var arc2 = d3.svg.arc()
.innerRadius(0)
.outerRadius(100)
.startAngle(0)
var svg = d3.select("body")
.append("svg")
.attr("width",width)
.attr("height",height)
.append("g")
.attr("transform", "translate(" + width/2 + "," + height/2 + ")")
//gray null background
var background = svg.append("path")
.datum({endAngle: tau})
.style("fill", "#ddd")
.attr("d", arc)
var center = svg.append("image")
.append("path")
.datum({endAngle: tau})
.attr("d", arc2)
.attr("class","record")
.attr("xlink:href", "http://lorempixel.com/g/400/400/")
好的謝謝,這確實很好。我唯一的問題是讓圖像恰好適合弧線間隙的大小。有沒有辦法做到這一點沒有硬編碼的大小/位置? – Pilkington