[Chartjs]-How to determine which bar was clicked on a chart js

1👍

After reading your comments and understanding your problem, I think I found a solution for you.

options:{
   onClick: function (event, elements){  
       if (elements.length > 0) {   
           // To get the clicked element
           const clickedElement = this.getElementAtEvent(event);

           // To get the group id of the clicked element
           const groupIndex = clickedElement[0]._index;

           // To get the id of the clicked element with in the group
           const barIndex = clickedElement[0]._datasetIndex;
       }
   }
}

This way you can know, what the clicked element is, which group/column it belongs to and which id it has within the group (i.e. which of the five bars were clicked).

1👍

You can try this code inside your chart declaration and load your html table data

options:{
       onClick: graphClickEvent
}

function graphClickEvent(event, array){
   if(array.length === 0){
     //load table
   }
}

Leave a comment