admin管理员组文章数量:1388039
How i can assign ids to raphaeljs bars in g.raphael barchart and how to access them after
var r = Raphael("holder", 600, 500);
var data=[1,3,4,5];
var chart = r.g.barchart(30, 30, 350, 250, [data], {stacked: true, type: "soft"});
for (var i = 0; i < chart.bars[0].length; i++) {
var bar = chart.bars[0][i];
if (bar.value >= 7) {
bar.attr("fill", "#bf2f2f");
bar.attr("stroke", "#bf2f2f");
bar.attr("id","id-"+i); //this doesn't work
bar.id="id-"+i; //this also doesn't work
//applied as per raphaeljs documentatoion
//[.html#Element.id][1]
}
}
How i can assign ids to raphaeljs bars in g.raphael barchart and how to access them after
var r = Raphael("holder", 600, 500);
var data=[1,3,4,5];
var chart = r.g.barchart(30, 30, 350, 250, [data], {stacked: true, type: "soft"});
for (var i = 0; i < chart.bars[0].length; i++) {
var bar = chart.bars[0][i];
if (bar.value >= 7) {
bar.attr("fill", "#bf2f2f");
bar.attr("stroke", "#bf2f2f");
bar.attr("id","id-"+i); //this doesn't work
bar.id="id-"+i; //this also doesn't work
//applied as per raphaeljs documentatoion
//[http://raphaeljs./reference.html#Element.id][1]
}
}
Share
Improve this question
asked Dec 15, 2011 at 18:34
Mujtaba HaiderMujtaba Haider
1,6502 gold badges19 silver badges29 bronze badges
2 Answers
Reset to default 5Try
bar[0].id = "id-"+i;
//or
bar.node.id = "id-"+i;
bar
is a Raphael element. Its [0]
and node
attributes point to the actual DOM element.
You could try this
bar.data("id" : +i)
More here: http://raphaeljs./reference.html#Element.data
本文标签: javascripthow i can assign ids to svg elements (to raphaeljs bars)Stack Overflow
版权声明:本文标题:javascript - how i can assign ids to svg elements? (to raphaeljs bars) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744560254a2612725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论