-1

I would like to know the "userId" custom property when I click on the element.

If I add a custom property to the dataset object, the custom property added doesn't show in the element retrieved in getElementAtEvent.

Arthur Menezes
  • 241
  • 5
  • 16

1 Answers1

0

Since you barely gave any specifications on where you tried accesing your custom property I went with that it was in the dataset itself, if this is the case you can acces it like this:

onClick: (evt, elements, chart) => {
    alert(chart.data.datasets[chart.getElementsAtEventForMode(evt, 'nearest', { intersect: true }, true)[0].datasetIndex].customProperty)
  }

Example: https://codesandbox.io/s/react-chartjs-2-bar-with-groups-and-patterns-forked-xeblf?file=/src/BarChart.js

LeeLenalee
  • 27,463
  • 6
  • 45
  • 69
  • I'm using react-chartjs-2 (2.10.0). In your code, you are using react-chartjs-3 (3.0.3). Could you answer in react-chartjs-2? – Arthur Menezes May 14 '21 at 20:55