March 19, 2012

How to add jquery click event to gRaphael graphics?

Question by 3gwebtrain

I made a chart using 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!
            })

})

Later I added the click event to pie.sector, but my event is not work… any one know the right way to handle gRaphael with jQuery?

Answer by Starx

Just select the pie

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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!