Ich versuche, eine Reihe von gekrümmten Textbögen zu erstellen. Wenn ich versuche und den Text in einen Kreis einfüge, wird er nicht angezeigt. Ich bin mir auch nicht sicher, wie ich die Ausrichtung des Textes steuern kann.d3.js Erstellen von Textbögen
Gibt es eine anspruchsvolle Art und Weise dies zu bauen - auch den Originaltext verstecken müssen - nicht sicher, ob ich den Text setzen wollen innerhalb eines anderen Daten
<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);
});
können Sie bitte einen Link zu einem Arbeitsbeispiel bereitstellen? – elias