d3の円グラフの例に従います。http://bl.ocks.org/mbostock/3887235です。テキストがd3円グラフのパスでカバーされています
私のコードの最小限のサンプル:
const container = $('#graph-pie');
const width = container.width() * 0.5;
const height = 256;
const radius = Math.min(width, height)/2;
const color = d3.scaleOrdinal()
.range(['#869099', '#8c7853', '#007d4a']);
const arc = d3.arc()
.outerRadius(radius - 10)
.innerRadius(0);
const labelArc = d3.arc()
.outerRadius(radius - 40)
.innerRadius(radius - 40);
const pie = d3.pie()
.sort(null)
.value((d) => { return d.value });
const svg = d3.select('#graph-pie').append('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', 'translate(' + width/2 + ',' + height/2 + ')');
const g = svg.selectAll('.arc')
.data(pie(totals))
.enter()
.append('g')
.attr('class', 'arc');
g.append('path')
.attr('d', arc)
.style('fill', (d) => { return color(d.data.name) });
g.append('text')
.attr('transform', (d) => { return 'translate(' + labelArc.centroid(d) + ')' })
.attr('dy', '.35em')
.text((d) => {
return names[d.data.name];
});
問題が時々ラベルのテキストは、円スライスの後ろに隠れて表示されていることです。私はこれがChromeで主に起こっていることに気付いていますが、他のブラウザでは起こっていないことはわかりません。いくつかの例:
ことができます場合は、次のように出力されたSVGのコードは次のとおりです。
<div id="graph-pie" class="graph pie">
<svg width="668" height="256">
<g transform="translate(334,128)">
<g class="arc">
<path d="M7.225416114969383e-15,-118A118,118,0,0,1,98.56840842206363,-64.87117126383073L0,0Z" style="fill: rgb(134, 144, 153); z-index: 10;">
<text transform="translate(41.753394753534344,-77.46388853237056)" dy=".35em">Sensitive</text>
</g>
<g class="arc">
<path d="M98.56840842206363,-64.87117126383073A118,118,0,0,1,-27.95807360901471,114.64007205193529L0,0Z" style="fill: rgb(140, 120, 83);">
<text transform="translate(71.92851960216296,50.69800851947991)" dy=".35em">Somewhat Sensitive</text>
</g>
<g class="arc">
<path d="M-27.95807360901471,114.64007205193529A118,118,0,0,1,-2.167624834490815e-14,-118L0,0Z" style="fill: rgb(0, 125, 74);">
<text transform="translate(-87.37132713286675,-10.500056906587716)" dy=".35em">Tolerant</text>
</g>
</g>
</svg>
</div>
私はいじり試してみましたz-index CSSスタイルですが、効果はなく、SVG要素のようには見えませんilar属性。テキスト要素をパスの上にレンダリングさせるにはどうすればよいですか?