insert new line in D3 text issue

7,160 views
Skip to first unread message

Kim

unread,
Jun 11, 2015, 9:47:51 PM6/11/15
to d3...@googlegroups.com
Hi All,
I had a hard time to insert the new character into my D3.text please help if you know the anwser.
d3text.html('abc' + '<br/>' + 'edf');

but it didn't work. The output is abcedf. 
Your help is greatly appreciated.
Kim

Micah Stubbs

unread,
Jun 12, 2015, 12:29:32 AM6/12/15
to d3...@googlegroups.com
Hi Kim!

for HTML text, this approach should work:


for SVG text however, displaying text on multiple lines is a bit more involved:


I hope that is helpful!

Kim

unread,
Jun 12, 2015, 12:40:58 PM6/12/15
to d3...@googlegroups.com
Hi Micah,
I have try this .html("test" + "<br/>" + "test") but it didn't work at all.
Any other suggestion.
Joanne

Chris Viau

unread,
Jun 13, 2015, 3:40:56 PM6/13/15
to d3...@googlegroups.com
As Micah said, <br/> works in html but not in SVG. In SVG, you can use tspan, which is not a direct equivalent: https://developer.mozilla.org/fr/docs/Web/SVG/Element/tspan You can also find d3 plugins for text wrapping, but I would encourage you to learn to use tspan.
ChrisV
Reply all
Reply to author
Forward
0 new messages