Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在饼图中添加onclick函数_Java_Javascript_Html_Snap.svg - Fatal编程技术网

Java 在饼图中添加onclick函数

Java 在饼图中添加onclick函数,java,javascript,html,snap.svg,Java,Javascript,Html,Snap.svg,我需要在我的项目中添加一个图,我尝试了一个免费的图(下面给出了链接) 我需要在饼图中添加一个onclick处理程序。我认为需要在内部添加onclick函数 snap.svg.js (在路径标签中)我尝试了很多,但没有成功 .onclick应设置为函数而不是字符串。试一试 elemm.onclick=function(){alert('blah');} 您可以使用jquery 如果要向切片添加单击事件,请执行以下操作: // this adds a click event to the fir

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

snap.svg.js

(在路径标签中)我尝试了很多,但没有成功


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

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

您可以使用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!');
  });

在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添加新事件