我正在嘗試創建一組曲線文本圓弧。當我嘗試並將文字放入圈中時,它不會顯示出來。我也不確定如何控制文本的方向。d3.js創建文本圓弧
是否有建立這個更復雜的方式 - 也需要隱藏原文 - 不知道如果我想將文本中的另一個數據屬性
<div data-type="curve">some text that needs</div>
function curveme(el){
var content = $(el).text();
//Create the SVG
var svg = d3.select(el).append("svg")
.attr("width", 400)
.attr("height", 120);
//Create an SVG path
svg.append("path")
.attr("id", "wavy") //very important to give the path element a unique ID to reference later
.attr("d", "M 10,90 Q 100,15 200,70 Q 340,140 400,30") //Notation for an SVG path, from bl.ocks.org/mbostock/2565344
.style("fill", "none")
.style("stroke", "#AAAAAA");
/*
var pi = Math.PI;
var arc = d3.arc()
.innerRadius(150)
.outerRadius(180)
.startAngle(0)
.endAngle(pi/2)
svg.append("path")
.attr("d", arc)
.attr("id", "wavy")
.attr("transform", "translate(200,200)")
.style("fill","none")
.style("stroke", "#AAAAAA");
*/
//Create an SVG text element and append a textPath element
svg.append("text")
.append("textPath") //append a textPath to the text element
.attr("xlink:href", "#wavy") //place the ID of the path here
.style("text-anchor","middle") //place the text halfway on the arc
.attr("startOffset", "50%")
.text(content);
}
$('[data-type="curve"]').each(function(index) {
curveme(this);
});
您能否提供一個鏈接到一個工作示例? – elias