Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  71] [ 4]  / answers: 1 / hits: 16722  / 13 Years ago, tue, november 15, 2011, 12:00:00

I want to add text to a element in raphael js,
I have added text with



r.text(30, 20, ellipse).attr({fill: color});


But how to add this text to



ec = r.ellipse(190, 100, 30, 20);


regards


More From » text

 Answers
99

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)

[#89109] Monday, November 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emilianoc

Total Points: 568
Total Questions: 109
Total Answers: 99

Location: Oman
Member since Sat, Jan 7, 2023
1 Year ago
;