Chartjs-How can i get the Chart JS Bar Graph Bar Label and Value on click?

0👍

You can use window.location.replace() to redirect to another page, and pass the parameters in a query string, like so:

onClick: function(c,chart_instances){
    try{
        ev = chart_instances[0];
        window.location.replace("./yourNextPage?label=" + this.data.labels[ev._index] + "&value=" + this.data.datasets.data[ev._index]);

    } catch (e){
        //ignore misclicks
    }
}

Refer to this question on instructions to retrieve the data from a query string in your next page.

Leave a comment