How to access custom property in dataset object in Bar Chart in React ChartJS 2?

๐Ÿ‘: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

Leave a comment