0

現在、円弧の中心に svg:image を配置しようとしています:

  var arcs = svg.selectAll("path");

arcs.append("svg:image")
.attr("xlink:href", "http://www.e-pint.com/epint.jpg ")
.attr("transform", function(d) { return "translate(" + arc.centroid(d) + ")"; })
.attr("width", "150px") 
.attr("height", "200px");

なぜ表示されないのか、どなたかアドバイスいただけると助かります

ありがとう: http://jsfiddle.net/xwZjN/17/

4

1 に答える 1

0

Looking at the jsfiddle, you are creating the path elements after you try to append the svg:image elements to the them. It should be the other way around. You should first create the arcs and then append the images.

Second, as far as I know, the svg:path element should not contain any svg:image tags. It doesn't seem to display them if you place some inside. Instead what you should do is create svg:g tags with class arc and then use those to place the svg:images

Slightly modifying your jsfiddle could look something like this:

var colours = ['#909090','#A8A8A8','#B8B8B8','#D0D0D0','#E8E8E8'];

var arcs = svg.selectAll("path");

for (var z=0; z<30; z++){
   arcs.data(donut(data1))
      .enter()
      //append the groups
      .append("svg:g")
      .attr("class", "arc")
      .append("svg:path")
      .attr("fill", function(d, i) { return colours[(Math.floor(z/6))]; })
      .attr("d", arc[z])
      .attr("stroke","black")
} 

//here we append images into arc groups
var pics = svg.selectAll(".arc").append("svg:image")
   .attr("xlink:href", "http://www.e-pint.com/epint.jpg ")
   .attr("transform", function(d,i) {
       //since you have an array of arc generators I used i to find the arc
       return "translate(" + arc[i].centroid(d) + ")"; })
   .attr("x",-5)
   .attr("y",-10)
   .attr("width", "10px") 
   .attr("height", "20px");

Where I also decreased the size of the images and offset them so that they fit into the arc.

于 2012-11-03T00:22:43.890 に答える