chartjs / chartjs/chartjs-plugin-datalabels
Horizontal stacked barchart with negative values label position is off
- Dominant language
- JavaScript
- Stars
- 920
- Forks
- 507
- PR merge metrics
- No merged PRs in 30d
Description
The sum of the bar is shown wrong when there are negative values it the stack and last stack value is 0 (which is so it is not shown in bar on the image)
```
datalabels: {
formatter: (value, ctx) => {
const datasets = ctx.chart.data.datasets;
if (datasets.indexOf(ctx.dataset) === datasets.length - 1) {
let sum = 0;
datasets.map((dataset) => {
sum += dataset.data[ctx.dataIndex] as number;
});
return sum.toFixed(2);
} else {
return '';
}
},
anchor: 'end',
align: 'end',
},
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.