question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stacked bar series with negative values are not drawn below 0 on the YAxis

See original GitHub issue

Stacked bar series with all positive values render as expected:

function Chart({data}) {
  return <XYPlot width={300} height={300} stackBy="y">
          <VerticalGridLines />
          <HorizontalGridLines />
          <XAxis />
          <YAxis />
          <VerticalBarSeries data={[{x: 1, y: 10}, {x: 2, y: 5}, {x: 3, y: 15}]} />
          <VerticalBarSeries data={[{x: 1, y: 12}, {x: 2, y: 2}, {x: 3, y: 11}]} />
          <VerticalBarSeries data={[{x: 1, y: 5}, {x: 2, y: 7}, {x: 3, y: 4}]} />
        </XYPlot>
}

image

However, if y-axis values are less than zero my expectation is that the bars with negative values will stack below 0 on the Y axis. However, they appear to draw downward from the top of the previous bar.

function Chart({data}) {
  return <XYPlot width={300} height={300} stackBy="y">
          <VerticalGridLines />
          <HorizontalGridLines />
          <XAxis />
          <YAxis />
          <VerticalBarSeries data={[{x: 1, y: 10}, {x: 2, y: 5}, {x: 3, y: 15}]} />
          <VerticalBarSeries data={[{x: 1, y: 12}, {x: 2, y: 2}, {x: 3, y: -5}]} />
          <VerticalBarSeries data={[{x: 1, y: 5}, {x: 2, y: 7}, {x: 3, y: -5}]} />
        </XYPlot>
}

image

Is there a way to configure the chart to stack all bars with negative values below 0 on the Y axis?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ABBVelocityDevcommented, Oct 15, 2018

Thank you for that direction. I’ve been able to achieve the desired result using the RectSeries. Thanks!

image

0reactions
Krustalcommented, Jan 2, 2019

@ABBVelocityDev would you be able to share an example?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Highcharts - Keep Zero Centered on Y-Axis with Negative ...
I have an area chart with negative values.
Read more >
StackedBar with Negative Values - changing center axis value
Currently, I have the value defaulting it to 0, but I would like to have that center stem have a value other than...
Read more >
Include negative value in sum/total value in stacked bar chart
The main issue is that your keys are not ordered appropriately. You need to move stack negative=on previous after ybar stacked .
Read more >
StackedArea Chart not showing series with negative values
The way it used to work was that a series with negative values would stack below the X Axis and positive value above....
Read more >
A Complete Guide to Stacked Bar Charts | Tutorial by Chartio
A line is plotted on top of these bars in order to show the net totals. When the secondary values are consistently positive...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found