Chartjs-Detect if the click is in bar or outside of bar in ChartJS

1👍

You get an array containing all the active elements as second argument so if this array has a length of 0 no bar has been clicked and if it has a length greater then 0 a bar has been clicked:

options: {
  onClick: function (evt, activeEls) {
    if (activeEls.length === 0) { 
      alert("clicked outside of bar");
    } else {
      alert("clicked on bar");
    }
  }
}

Leave a comment