2012-03-19 84 views
4

我做了使用g.Raphael圖表:如何將jquery點擊事件添加到gRaphael圖形?

$(function(){ 
    var r = Raphael("pieChart"), 
      pie = r.piechart(320, 240, 100, [55, 20, 13, 32, 5, 1, 2, 10]); 

      r.text(320, 100, "Interactive Pie Chart").attr({ font: "20px sans-serif" }); 
      $(pie.sector).click(function(){ 
       alert('hi');//not work! 
      }) 

}) 

後來我加入了點擊事件pie.sector,但我的事件是不行的......任何一個知道用jQuery來處理gRaphael的正確方法?

回答

0

只需選擇餡餅

$(pie).click(function(){ 
    alert('hi'); 
}) 
+0

我需要添加不同的事件與每個部門... – 3gwebtrain 2012-03-19 13:28:44

4

在這裏你去

遍歷你的圓形切片,並添加單擊處理程序到他們

for(var index_i=0;index_i < pie.covers.items.length;index_i++){ 
    pie.covers.items[index_i].click(clickSomeSlice); 
} 


var clickSomeSlice = function() { 
    alert("clicked on\t"+this.label[1].attrs.text); 
}; 

Here a complete jsfiddle example

相關問題