[Chartjs]-Chart Js clickable bar

27👍

If you are using chart.js version 2.4+ (maybe earlier), there is a onclick event that is very useful. I’m using it on a stacked bar chart, so it should work for you too. You can find it under common chart configuration in the documentation. (See: https://www.chartjs.org/docs/latest/charts/bar.html#stacked-bar-chart)

options:{
    onClick: graphClickEvent
}

function graphClickEvent(event, array){
    if(array[0]){
       foo.bar;
    }
}

Hope this helps.

Leave a comment