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
Add a ment  | 

2 Answers 2

Reset to default 5

Try

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