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

Negative numbers do not render in bar chart when there is only one key #165

Closed
barrylapthorn opened this issue Mar 29, 2018 · 15 comments
Closed
Labels
📊 bar @nivo/bar package bug

Comments

@barrylapthorn
Copy link

Take the example here:

http://nivo.rocks/storybook/?selectedKind=Bar&selectedStory=stacked%20horizontal&full=0&down=1&left=1&panelRight=0&downPanel=storybooks%2Fstorybook-addon-knobs

Change the data to have negative values, and have only one key field:

<Bar
  width={1000}
  height={600}
  margin={{top: {60}, right: {80}, bottom: {60}, left: {80}}}
  data={[{{country: "AD", hot dogs: {-55}}}, {{country: "AE", hot dogs: {7}}}]}
  indexBy="country"
  keys={["hot dogs"]}
  padding={0.2}
  labelTextColor="inherit:darker(1.4)"
  labelSkipWidth={16}
  labelSkipHeight={16}
  layout="horizontal"
  enableGridY={false}
  enableGridX
/>

and the negative value bars do not render.

But adding an extra key makes it work, i.e.

  keys={["hot dogs", "FOO"]}

or

  keys={["hot dogs", ""]}
@20ali20
Copy link

20ali20 commented Apr 3, 2018

margin={{top: 60, right: 80, bottom: 60, left: 80}}

@20ali20
Copy link

20ali20 commented Apr 3, 2018

data={[{{country: "AD", hot dogs: -55}}, {{country: "AE", hot dogs: 7}}]}

@20ali20
Copy link

20ali20 commented Apr 3, 2018

dont put values inside { }

@plouc plouc added 📊 bar @nivo/bar package bug labels May 18, 2018
@plouc
Copy link
Owner

plouc commented May 19, 2018

Example for reference => https://codesandbox.io/s/k346rpz98v

@mjsarfatti
Copy link
Contributor

Same problem here. And adding one empty key does fix it, even though it seems hacky :)

@pfreedmanJG
Copy link

Example for reference => https://codesandbox.io/s/k346rpz98v

Can someone share a version of this with the workaround please? I can't get the negative bar to render.

@zepplock
Copy link

So what is the right way to fix this?

@20ali20
Copy link

20ali20 commented Dec 13, 2018

@zepplock did you actually look at the first 3 posts I made and try those codes?

@zepplock
Copy link

I did, if I add a new "foo" key like original poster suggested it works, but this looks like a hack, right?

@20ali20
Copy link

20ali20 commented Dec 13, 2018

@zepplock I was talking about my posts. The original poster suggestions is hacky.
What I suggested is what works because his code seems to have some syntax issue.
Just Check the first two posts I made and replace them where its needed from the original code.

@zepplock
Copy link

I tried your suggestions but there's still an issue. Take a look at codesandbox link @pluoc posted. It has no negative value unless you add "FOO" to the list of keys.

@20ali20
Copy link

20ali20 commented Dec 13, 2018

Gotcha. That is definitely hacky but I think that empty key acts as a baseline so the negative values can be rendered.
But a hacky way that won't really affect anything is not really a deal breaker ;)

@brunovegreville
Copy link

This seems to be related to this d3-shape issue : d3/d3-shape#114

@sdzaveri
Copy link

Experiencing this issue as well, looks like a simple fix was also created d3/d3-shape#115

@wyze
Copy link
Contributor

wyze commented Jun 4, 2021

Going to close this as it appears to be fixed now.

@wyze wyze closed this as completed Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📊 bar @nivo/bar package bug
9 participants