【问题标题】:How to add jquery click event to gRaphael graphics?如何将 jquery 点击事件添加到 gRaphael 图形?
【发布时间】:2012-04-03 19:02:04
【问题描述】:

我用 g.Raphael 做了一个图表:

$(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的正确方法吗?

【问题讨论】:

    标签: jquery graphael


    【解决方案1】:

    给你

    遍历你的饼图并向它们添加点击处理程序

    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

    【讨论】:

      【解决方案2】:

      只需选择饼图

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

      【讨论】:

        猜你喜欢
        • 2010-12-09
        • 1970-01-01
        • 2013-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-26
        • 1970-01-01
        • 2013-06-13
        相关资源
        最近更新 更多