I'm working with codepen.io and I am creating a paragraph. The graph has a title.
The problem is that I want the title center-aligned.It should automatically set the title in the middle, not about editing the value of "x". I can't use CSS to do this, and I believe javascript would do the job.
Here are the one functions I am using to draw the title and the link to my project goes bellow.
var text = document.createElementNS(svgNS,"text");
text.setAttributeNS(null, 'x', 100);
text.setAttributeNS(null, 'y', 15);
text.textContent = (titel);
document.getElementById("bargraph").appendChild(text);
Full code:
var text = document.createElementNS(svgNS,"text");
text.setAttributeNS(null, 'y', 15);
text.textContent = (titel);
document.getElementById("bargraph").appendChild(text);
text.setAttributeNS(null, 'x', 300 / 2 - text.getBBox().width /2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.