3

我需要在我的项目中添加一个图表,我尝试了一个免费图表(链接如下)我需要向该饼图添加一个 onclick 处理程序。我认为需要在里面添加onclick函数

snap.svg.js

(在路径标签中)我尝试了很多但没有得到

http://www.jqueryscript.net/demo/Responsive-Pie-Chart-Plugin-wit-jQuery-Snap-SVG-Pizza

4

3 回答 3

0

你可以使用jquery

如果要向切片添加点击事件:

  // this adds a click event to the first slice
  $("path[data-id='s0']").click(function() {
     alert('you clicked slice one');
  });

  // if you have multiple pie's you can be more specific
  $("#svg svg path[data-id='s0']").click(function(){
     alert('you just clicked pie with id #svg');
  });

如果要向整个饼图添加点击事件:

  $('#svg').click(function(e){
      alert('you just clicked the whole pie!');
  });
于 2014-01-17T10:20:46.760 回答
0

.onclick 应设置为函数而不是字符串。尝试

elemm.onclick = function() { alert('blah'); };

于 2014-01-17T09:52:31.823 回答
0

在您的 Pizza.js 文件中,您可以在 Snap.svg 之后添加一个 onclick 侦听器

   pie : function (legend) {
      // pie chart concept from JavaScript the 
      // Definitive Guide 6th edition by David Flanagan
      ...

        path.node.setAttribute('data-id', 's' + i);

        //============= You could add your listener here
        path.click(alert("My click function"));
        //===============================================


        this.animate(path, cx, cy, settings);

        // The next wedge begins where this one ends
        start_angle = end_angle;
      }

  return [legend, svg.node];
},

另一种选择是尝试通过 events {} @ Pizza.js 添加新事件

于 2014-01-17T10:44:18.400 回答