开发者

Raphaeljs charts bar index fetching

Is there a way to get a bar's index value?

开发者_如何学Python

So for example

bar_chart.hover(function() { 
        var test = this.bar.index; 
}); 

Or something to that effect? Basically, if the bar chart consists of 10 colums and I click on the third, I would want the value 3 returned.

Thanks in advance.

David


First assign an index to each bar, by adding an attribute called "index" to it:

(function() {
    var i = 0;
    bar_chart.each(function(one_bar) { 
        one_bar.index = i++;
    });
})();

Then you can use exactly the syntax you suggested:

bar_chart.hover(function() { 
        var test = this.bar.index; 
}); 


Bosh almost got it. This code worked for me:

    var i = barchart.bars.length;
    barchart.each(function() {
        this.bar.index = --i;
    });


or -

 for (i = 0; i < iMax; i++) {
  chart.bars[0][i].myIndex = i;
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜