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 Charts Label show wrong value #1992

Closed
1 task done
arigon opened this issue Jan 16, 2020 · 4 comments
Closed
1 task done

Stacked Bar Charts Label show wrong value #1992

arigon opened this issue Jan 16, 2020 · 4 comments

Comments

@arigon
Copy link

arigon commented Jan 16, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Creating a stacked Bar Chart and enable label attribute.

What is expected?

Showing the value of each stacked bar

What is actually happening?

It shows the correct value of the first stacked bar, but it shows the sum of the first value and the value of the second stack in the second one. The same with the third one: it shows the sum of all three bars instead of only one.

Environment Info
Recharts v1.8.5
React 16.8.2
System MacOS
Browser Chrome
@mwskwong
Copy link

You are talking about Stacked Bar Charts but your codesandbox has a Line Chart example...

@arigon
Copy link
Author

arigon commented Jan 21, 2020

You are talking about Stacked Bar Charts but your codesandbox has a Line Chart example...

Ah, sorry. I thought codesandbox is saving changes automatically. Now it should be working. :-)

@mariopeixoto
Copy link

Same issue here... looks like when the bar is stacked, the label is being rendered as the sum of all the values below that item instead of the individual values...

@mariopeixoto
Copy link

Here is a workaround:

const valueAccessor = attribute => ({ payload }) => {
  return payload[attribute];
};

....
      <Bar dataKey="0" stackId="a" fill="#8884d8">
        <LabelList valueAccessor={valueAccessor("0")} />
      </Bar>
      <Bar dataKey="1" stackId="a" fill="#82ca9d">
        <LabelList valueAccessor={valueAccessor("1")} />
      </Bar>
      <Bar dataKey="2" stackId="a" fill="#82ca9d">
        <LabelList valueAccessor={valueAccessor("2")} />
      </Bar>
...

On codesandbox:
https://codesandbox.io/s/recharts-issue-template-70kry

@xile611 xile611 closed this as completed May 11, 2020
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

4 participants