How to add text to a raphael js element

半城伤御伤魂 提交于 2019-12-04 01:47:18

Raphael does not have child/parent relationship between elements, so you will set same position for them e.g.

ec = paper.ellipse(190, 100, 30, 20);
paper.text(190, 100, "ellipse").attr({fill: '#ff0000'});

So if you want a ellipse with text, create your own JavaScript object which handles positioning of both.

or alternate way is to group elements via set e.g.

var eltext = paper.set();
el = paper.ellipse(0, 0, 30, 20);
text = paper.text(0, 0, "ellipse").attr({fill: '#ff0000'})
eltext.push(el);
eltext.push(text);
eltext.translate(100,100)

You can easly add text to youR elements creating a text Raphael element and add as attribute text into your element.

 elText = r.text(.....);
 yourEl.attr({text:elText});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!