title: Binding to Click Events for Pie Chart - Plotly - JavaScript
body: <p>How to convert the <code>plotly</code> binding click event for a pie chart?</p>
  
  <p>What I currently have below is for a <a href="https://plot.ly/javascript/click-events/" rel="nofollow noreferrer">plotly scatter</a> graph, but I am unsure how to use the same concept for a pie chart. </p>
  
  <pre><code>var myPlot = document.getElementById('myDiv'),
      d3 = Plotly.d3,
      N = 16,
      x = d3.range(N),
      y = d3.range(N).map( d3.random.normal() ),
      data = [ { x:x, y:y, type:'scatter',
              mode:'markers', marker:{size:16} } ],
      layout = {
          hovermode:'closest',
          title:'Click on Points'
       };
  
  Plotly.newPlot('myDiv', data, layout);
  
  myPlot.on('plotly_click', function(data){
      var pts = '';
      for(var i=0; i &lt; data.points.length; i++){
          pts = 'x = '+data.points[i].x +'\ny = '+
              data.points[i].y.toPrecision(4) + '\n\n';
      }
      alert('Closest point clicked:\n\n'+pts);
  });
  </code></pre>