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

Stacked Bar Chart with Groups wrong order when hiding the first dataset by clicking on the legend #11978

Open
ACEMerlin opened this issue Dec 16, 2024 · 0 comments

Comments

@ACEMerlin
Copy link

Expected behavior

stack bar order stays the same

Current behavior

stack bar order is changed

Reproducible sample

I used the 'Stacked group bar' demo to reproduce this:

Optional extra steps/info to reproduce

const DATA_COUNT = 7;
const NUMBER_CFG = {count: DATA_COUNT, min: -100, max: 100};

const labels = Utils.months({count: 7});
const data = {
  labels: labels,
  datasets: [
    {
      label: 'Comp 1',
      data: Utils.numbers(NUMBER_CFG),
      backgroundColor: Utils.CHART_COLORS.red,
      stack: 'Stack 0',
    },
    {
      label: 'Data 1',
      data: Utils.numbers(NUMBER_CFG),
      backgroundColor: Utils.CHART_COLORS.blue,
      stack: 'Stack 1',
    },
    {
      label: 'Comp 2',
      data: Utils.numbers(NUMBER_CFG),
      backgroundColor: Utils.CHART_COLORS.green,
      stack: 'Stack 0',
    },
    {
      label: 'Data 2',
      data: Utils.numbers(NUMBER_CFG),
      backgroundColor: Utils.CHART_COLORS.black,
      stack: 'Stack 1',
    }
  ]
};
  • as you can see the 'Comp x' (stack 0) should be on the left side of 'Data x' (stack 1).
  • now hide Comp 1 by clicking on the legend 'Comp 1'
  • Weird things happen: now stack 1 is on the left side of stack 0

Possible solution

No response

Context

Question:

  • how to keep stack 0 always on the left side
  • or this there a way to order the 'stacks'

chart.js version

v4.4.3

Browser name and version

No response

Link to your project

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant