Chartjs-Chart.js: Is it possible to get the label of a dataset in a stacked bargraph on clicking it?

0👍

You can use the prototype method .getElementAtEvent(e) to get the element clicked on like so

onClick: function(evt, element) {
  var activePoints = bar_chart.getElementAtEvent(evt);
  console.log(activePoints[0]._model.datasetLabel);
}

JSFiddle

Or you can attach it as an event handler on the chart element

bar_ctx.onclick = function(evt) {
  var activePoints = bar_chart.getElementAtEvent(evt);
  console.log(activePoints[0]._model.datasetLabel);
};

JSFiddle

Leave a comment