Javascript Raphaeljs将单击事件添加到饼图的一部分
我需要对Raphael饼图中每个切片上的单击事件做出响应。我这样试过,但似乎不行。在下面的代码中,我的代码只有两行被注释为我的代码,它直接来自RaphaelJS的演示饼图Javascript Raphaeljs将单击事件添加到饼图的一部分,javascript,jquery,css,svg,Javascript,Jquery,Css,Svg,我需要对Raphael饼图中每个切片上的单击事件做出响应。我这样试过,但似乎不行。在下面的代码中,我的代码只有两行被注释为我的代码,它直接来自RaphaelJS的演示饼图 <script> var u = ""; var r = ""; window.onload = function () { r = Raphael("holder"), pie = r.pie
<script>
var u = "";
var r = "";
window.onload = function () {
r = Raphael("holder"),
pie = r.piechart(320, 240, 100, [25, 20, 13, 32, 5, 21, 14, 10,41,16,12,18,16,14,12,13],
{ legend: ["%%.%% - Enterprise Users", "IE Users"],
legendpos: "west", href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]
}
);
r.text(320, 100, "Interactive Pie Chart").attr({ font: "20px sans-serif" });
pie.hover(function () {
u = this; // My Code
u.onclick = clickEvent; // hook to the function
this.sector.stop();
this.sector.scale(1.1, 1.1, this.cx, this.cy); // Scale slice
if (this.label) { // Scale button and bolden text
this.label[0].stop();
this.label[0].attr({ r: 7.5 });
this.label[1].attr({ "font-weight": 800 });
}
}, function () {
this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
if (this.label) {
this.label[0].animate({ r: 5 }, 1500, "bounce");
this.label[1].attr({ "font-weight": 400 });
}
});
};
function clickEvent(){
console.log("Clicked!")
}
</script>
拉斐尔的语法有点不同 检查这个 您的代码应如下所示:
u.click(clickEvent);
是否有在悬停事件中附加click事件的原因?在悬停之外执行pie.onclick=clickEvent似乎更为正确function@ShanRobertson我需要在每一片上触发。切片具有子组,因此单击然后请求新数据,该数据将展开为不同的饼图。这种情况可能会持续几级。基本上是一种深入调查的情况。无论如何,谢谢你的回复…谢谢你的建议,但这是我在阅读了拉斐尔的文档之后尝试的第一件事。但它没有对此作出回应。尽管如此,我还是感谢你的帮助。我找到了解决方案,有空的时候会把它贴出来。我还得问问拉斐尔的创造者。。。