chartjs / chartjs-plugin-datalabels

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

Documentation lists undefined labels and is missing the complete type of context for formatter #343

Open tdauth opened 2 years ago

tdauth commented 2 years ago

Hi, I am using this plugin to show the labels of the datasets inside the bars. Hence, I customize the formatter. The example values from the documentation (https://v2_1_0--chartjs-plugin-datalabels.netlify.app/guide/formatting.html#custom-labels):

context.dataset.data[context.dataIndex].label;  // labels in each data object
context.dataset.labels[context.dataIndex];      // labels store in the dataset
globalLabels[context.dataIndex];                // labels store outside the chart

seem to be rather useless here. They were undefined except for the first one. By setting a breakpoint I discovered that my dataset had in fact one label:

context.dataset.label

Maybe add more example values or document the context type. I guess the values depend on which values your dataset has (for example not all datasets have a 'stack' member).