Create text in SVG

Source: Internet
Author: User

Since SVG cannot display line breaks, multiple texts must be created. How to create it? The following is an online example. It is not easy to find and transfer it.

Http://osdir.com/ml/text.xml.svg.devel/2002-08/msg01252.html)

 

Node = svgdoc. createelement ("text ");
Node. setattribute ("ID", yourid );
Node. setattribute ("X", yourx );
Node. setattribute ("Y", youry );
Node. setattribute ("style", yourstyle );
Textnode = svgdoc. createtextnode ("Hello dynamic text ");
Node. appendchild (textnode );
Yourparent. appendchild (node );

This shoshould do the job...

The only difference is that you have to create a special textnode that will be
Appended to the text-element, which is then appended to it's parent.

Hope this helps,
Andreas

--- In SVG-developers @ XXXX, "dennis_joel_david" <Dennis. myren @ XXXX> wrote:
>Isnt it possible todynamically create a text element and setting its

>Text?

>I am trying to use this function to achieve this.

>This doesnt work, but it seems like when I have already a text

>Element with this ID, and where text is more than empty string

>Already, there is no problem.

>What am I doing wrong?

>Because it has to be possible, because I dont know how plain text

>Elements will be created during the session when my SVG document

>Loads.

>Thank you

>Dennis

>Function createtextelement (text, x, y)

>{

>IND = _ osvgdoc. createelement ('text ');

>Ind. setattribute ('id', '123 ');

>Ind. setattribute ('x', x + (width/2 ));

>Ind. setattribute ('y', Y + (height/2) + 10 );

>Ind. setattribute ('style', 'text-anchor: middle; font-size: 16; font-

>Family: Arial; fill: black ;');

>Ind. setdata ('kalle ');

>// Ind. getfirstchild (). setdata ('kalle ');

>Parent. appendchild (IND );

>}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.