【发布时间】:2021-04-15 04:08:27
【问题描述】:
d3.js 有这个问题:我想将文本放在弧上。现在我使用的是textPath,效果是这样的:
有没有办法旋转 textPath?我想得到这样的效果:
这是我的代码:
path.attr("d",d3.arc()
.innerRadius(5)
.outerRadius(55)
.startAngle(Math.PI/2+angle-10 * (Math.PI / 180)) //converting from degs to radians
.endAngle(Math.PI/2+angle+10*(Math.PI/180)))
.attr("transform", function(d){return "translate("+d.x+","+d.y+") rotate("+nodesMap.get(node.id).degPathRotate+")"; })
.attr("fill", function(d) { return "red"; })
.attr("opacity", 0.8)
invisibleMap.get(node.id).angle = angle;
vis.append("text")
.append("textPath") //append a textPath to the text element
.attr("xlink:href", "#"+'p'+node.id) //place the ID of the path here
.text((nodesMap.get(node.id).totRels-nodesMap.get(node.id).shownRels))
【问题讨论】:
标签: javascript d3.js text path