title: Chart.js: Bar Chart Click Events
body: <p>I've just started working with Chart.js, and I am getting very frustrated very quickly. I have my stacked bar chart working, but I can't get the click "events" to work.</p>
  
  <p>I have found a <a href="https://github.com/chartjs/Chart.js/issues/577#issuecomment-55897221">comment on GitHub by <code>nnnick</code></a> from Chart.js stating to use the function <code>getBarsAtEvent</code>, even though this function cannot be found in the <a href="http://www.chartjs.org/docs/#bar-chart-chart-options">Chart.js documentation</a> at all (go ahead, do a search for it). The documentation does mention the <code>getElementsAtEvent</code> function of the <code>chart</code> reference, but that is for Line Charts only.</p>
  
  <p>I set an event listener (the right way) on my canvas element:</p>
  
  <pre><code>canv.addEventListener('click', handleClick, false);
  </code></pre>
  
  <p>...yet in my <code>handleClick</code> function, <code>chart.getBarsAtEvent</code> is undefined!</p>
  
  <p>Now, in the Chart.js document, there is a statement about a different way to register the click event for the bar chart. It is much different than <code>nnnick</code>'s comment on GitHub from 2 years ago.</p>
  
  <p>In the <a href="http://www.chartjs.org/docs/#getting-started-global-chart-configuration">Global Chart Defaults</a> you can set an <code>onClick</code> function for your chart. I added an <code>onClick</code> function to my chart configuration, and it did nothing...</p>
  
  <p>So, how the heck do I get the on-click-callback to work for my bar chart?!</p>
  
  <p>Any help would be greatly appreciated. Thanks!</p>
  
  <p><strong>P.S.:</strong> I am not using the master build from GitHub. I tried, but it kept screaming that <code>require is undefined</code> and I was not ready to include CommonJS just so that I could use this chart library. I would rather write my own dang charts. Instead, I downloaded and am using the <a href="https://raw.githubusercontent.com/nnnick/Chart.js/v2.0-dev/dist/Chart.js"><strong>Standard Build</strong></a> version that I downloaded straight from the link at the top of the <a href="http://www.chartjs.org/docs/">documentation page</a>.</p>
  
  <p><strong>EXAMPLE:</strong> Here is an example of the configuration I am using:</p>
  
  <pre><code>var chart_config = {
      type: 'bar',
      data: {
          labels: ['One', 'Two', 'Three'],
          datasets: [
              {
                  label: 'Dataset 1',
                  backgroundColor: '#848484',
                  data: [4, 2, 6]
              },
              {
                  label: 'Dataset 2',
                  backgroundColor: '#848484',
                  data: [1, 6, 3]
              },
              {
                  label: 'Dataset 3',
                  backgroundColor: '#848484',
                  data: [7, 5, 2]
              }
          ]
      },
      options: {
          title: {
              display: false,
              text: 'Stacked Bars'
          },
          tooltips: {
              mode: 'label'
          },
          responsive: true,
          maintainAspectRatio: false,
          scales: {
              xAxes: [
                  {
                      stacked: true
                  }
              ],
              yAxes: [
                  {
                      stacked: true
                  }
              ]
          },
          onClick: handleClick
      }
  };
  </code></pre>