chartjs / chartjs-plugin-datalabels

Chart.js plugin to display labels on data elements
https://chartjs-plugin-datalabels.netlify.app
MIT License
863 stars 460 forks source link

datalabels not showing up original data #313

Closed kbabraj closed 1 year ago

kbabraj commented 2 years ago

I am creating the bar chart with below combination, all good only the issue is 'datalabels" shows up the calculated value as default after mouse over the original data comes up. any help would be great.

"chart.js": "^3.7.1",
"chartjs-plugin-datalabels": "^2.0.0",
"chartjs-plugin-stacked100": "^1.2.0",

When I use the below code it's throws error originalData is not a property.

plugins: { display: true, datalabels: { display: true, formatter: (value, context) => { const data = context.chart.data; const datasetIndex = context.datasetIndex; const dataIndex = context.dataIndex; if (data.originalData[datasetIndex][dataIndex] === 0) { return ''; } return data.originalData[datasetIndex][dataIndex]; } }, stacked100: {enable: true} }

LeeLenaleee commented 2 years ago

not sure where you got originalData from since its nowhere in the documentation. The error is correct, there is not property called originalData on the data object. You need to target the datasets property