I have made various donut charts using D3js and I need to insert one same image inside the donut, but I can't figure out the way to achieve this. Can anyone help me with this? here's my JS code:
var data1 = [4,96];
var data2 = [1,99];
var data3 = [16,84];
var data4 = [12,88];
var data5 = [29,71];
var data6 = [15,85];
var data7 = [12,88];
var data8 = [10,90];
/* Reusable Drawing donut function*/
var width = 300,
height = 300,
radius = (Math.min(width, height) / 2) - 100;
function drawDonut(dataa,divchart){
var sym = "%"
var color = ["#00338D","#BC204B"];
var pie = d3.pie()
.value(function(d) { return d })(dataa);
var arc = d3.arc()
.outerRadius(radius - 10)
.innerRadius(radius - (radius/1.9));
var labelArc = d3.arc()
.outerRadius(radius - 31)
.innerRadius(radius - 31);
var svg = d3.select(divchart)
.append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" +60 + "," + 60 +")");
var g = svg.selectAll("arc")
.data(pie)
.enter().append("g")
.attr("class", "arc");
g.append("path")
.attr("d", arc)
.data(color)
.style("fill", function(d){return d});
}
drawDonut(data1,"#pie1")
drawDonut(data2,"#pie2")
drawDonut(data3,"#pie3")
drawDonut(data4,"#pie4")
drawDonut(data5,"#pie5")
drawDonut(data6,"#pie6")
drawDonut(data7,"#pie7")
drawDonut(data8,"#pie8")
the image I want to insert is a svg one, this is the code:
<g>
<path class="st0" d="M15.6,10.9c1.3,0,2.4-1.2,2.4-2.7c0-1.5-1.1-2.7-2.4-2.7c-1.3,0-2.4,1.2-2.4,2.7C13.2,9.7,14.2,10.9,15.6,10.9
L15.6,10.9z"/>
<path class="st0" d="M18.6,11.6h-1.2l-1.8,5.5l-1.8-5.5h-1.2c-1.3,0-2.4,1.2-2.4,2.7v13h2.4l1.2,16.4h3.6l1.2-16.4H21v-13
C21,12.8,19.9,11.6,18.6,11.6L18.6,11.6z"/>
<path class="st0" d="M31.9,10.9c1.3,0,2.4-1.2,2.4-2.7c0-1.5-1.1-2.7-2.4-2.7c-1.3,0-2.4,1.2-2.4,2.7C29.5,9.7,30.6,10.9,31.9,10.9
L31.9,10.9z"/>
<path class="st0" d="M39.8,25.2l-3.6-11.6c0,0-0.6-2-2.4-2h-3.6c-1.8,0-2.4,2-2.4,2l-3.6,11.6l1.2,0.7l4.2-9.5l-3.6,14.3h3.6
l1.2,13h2.4l1.2-13H38l-3.6-14.3l4.2,9.5L39.8,25.2L39.8,25.2z"/>
</g>
can you help me decifer how to insert the image in the hole of the donut chart please? thank you
See Question&Answers more detail:
os