Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal stacked barchart with negative values label position is off #407

Open
aapjaapan opened this issue Jan 16, 2024 · 0 comments
Open

Comments

@aapjaapan
Copy link

aapjaapan commented Jan 16, 2024

Screenshot 2024-01-16 at 10 51 38 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',
      },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant