Raphaeljs charts bar index fetching
Is there a way to get a bar's index value?
开发者_如何学PythonSo 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;
}
精彩评论