chartjs / chartjs/Chart.js

Stacked bar charts: doesn't stack multiple datas with same x coordinate for one dataset

Open
#11,202 0 comments 3 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

I was expecting all datas to be stacked.

### Current behavior

In my example, I have always 2 values in same x coordinate ( one positive, one negative ). As you can see, the bars above 0 are not stacked whereas the ones below 0 are.

![Capture d’écran du 2023-03-24 15-08-18](https://user-images.githubusercontent.com/57755769/227544484-b95051f7-7042-4033-8f33-a0a689a607a0.png)
l)

### Reproducible sample

https://jsfiddle.net/6b7gweps/

### Optional extra steps/info to reproduce

_No response_

### Possible solution

- Changes on the function that performs the stack to stack every datas.

- Maybe add a stackBy property to tell the chart which property of the data you want to use to perform the stack
Example of one data object:
```
{
x: string,
y: number,
positive: boolean
}
```
And on the chart configuration:
`stackBy:['x','positive']`

### Context

I am using the stacked bar charts to represent the traffic In and traffic Out in bytes for multiple interfaces

### chart.js version

v4.2.1

### Browser name and version

_No response_

### Link to your project

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.