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 do not render correctly with Positive / Negative Values #1280

Closed
bvader opened this issue Aug 2, 2021 · 6 comments · Fixed by #1502
Closed

Stacked bar charts do not render correctly with Positive / Negative Values #1280

bvader opened this issue Aug 2, 2021 · 6 comments · Fixed by #1502
Assignees
Labels
bug Something isn't working :chart Chart element related issue Impact:High kibana cross issue Has a Kibana issue counterpart :Lens Kibana Lens related issue :xy Bar/Line/Area chart related

Comments

@bvader
Copy link

bvader commented Aug 2, 2021

Describe the bug
Stacked bar charts do not render correctly with Positive / Negative Values
Also see Discuss Here

To Reproduce
Steps to reproduce the behavior:
Add the sample data below
Create a Non-Stacked and Stacked Lens Visualizations
Observe Correct Non-Stacked Bar Chart
Observer Incorrect Stacked Chart

Expected behaviour
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Version (please complete the following information):

  • OS: [e.g. iOS]
  • Browser: [e.g. chrome, safari]
  • Elastic Charts: [e.g. 1.0.1] 7.13.4, 7.14.0-SNAPSHOT

Sample Data

DELETE discuss-pos-neg

PUT discuss-pos-neg/
{
  "mappings": {
    "properties": {
      "category" : {"type": "keyword"},
      "value" : {"type": "float"}
    }
  }
}


POST discuss-pos-neg/_doc
{
      "category" : "10-20",
      "value" : 32
}

POST discuss-pos-neg/_doc
{
      "category" : "10-20",
      "value" : -45
}


POST discuss-pos-neg/_doc
{
      "category" : "20-30",
      "value" : 64
}

POST discuss-pos-neg/_doc
{
      "category" : "20-30",
      "value" : -23
}

POST discuss-pos-neg/_doc
{
      "category" : "30-40",
      "value" : 57
}

POST discuss-pos-neg/_doc
{
      "category" : "30-40",
      "value" : -33
}

GET discuss-pos-neg/_search

Non Stacked Chart Looks Correct

Screen Shot 2021-08-02 at 6 06 03 AM

Stacked Chart is Not Correct. It should look the same as above bu on the same line / category.

Screen Shot 2021-08-02 at 6 06 15 AM

@bvader bvader added the bug Something isn't working label Aug 2, 2021
@markov00 markov00 added :chart Chart element related issue :xy Bar/Line/Area chart related Impact:High labels Aug 2, 2021
@ghudgins ghudgins changed the title [LENS] Stacked bar charts do not render correctly with Positive / Negative Values Stacked bar charts do not render correctly with Positive / Negative Values Aug 2, 2021
@nickofthyme
Copy link
Collaborator

See reproduction codesandbox

@nickofthyme
Copy link
Collaborator

@monfera @markov00 what do you think the solution is here?

It seems like the only way to achieve the stacked result is to group the bars by polarity to not occlude other positive bars.

image

@markov00
Copy link
Member

@nickofthyme yep you are right, positive bars should be stacked with positive ones, negative with negative ones. @monfera do you see any drawback?

@monfera
Copy link
Contributor

monfera commented Aug 26, 2021

Indeed if we decide to support this "gross type" of stacking, all positives should be above zero and all negatives below zero. But it's not a good visualization in my opinion to begin with. Even something like a clustered bar chart, with every second bar showing negatives/positives for the same bin would be an improvement. Waterfall chart would be better, though we have no support for it right now

@markov00
Copy link
Member

markov00 commented Aug 27, 2021

The clustered bar chart example here looks good to you?

image

@dej611 dej611 added :Lens Kibana Lens related issue kibana cross issue Has a Kibana issue counterpart labels Nov 10, 2021
@dej611
Copy link
Contributor

dej611 commented Nov 10, 2021

More examples from this cross Kibana issue:

Screenshot 2021-11-09 at 19 08 36

Screenshot 2021-11-09 at 19 08 45

Screenshot 2021-11-09 at 19 12 50

Screenshot 2021-11-09 at 19 12 57

Screenshot 2021-11-09 at 19 12 04

Screenshot 2021-11-09 at 19 12 13

elastic/kibana#118066

As shown in the pictures, the order of the series matter, while the example from @nickofthyme seems more robust, to me.

nickofthyme added a commit that referenced this issue Dec 9, 2021
Resolves issue with stacking a mix of negative and positive bars and areas for any `StackMode`. Key changes include:

- Disallowing stacked band charts (i.e. using `stackAccessors` with `y0Accessors`). Now shows `console.warn` when used and ignores `y0Accessor` for rendering but still adds to `initialY0` value.
- Blocks showing banded legend and tooltip values for banded stacks, see case above.
- Prevents percentage domain constraining when no `stackAccessors` are specified.

fix #1280
nickofthyme pushed a commit that referenced this issue Dec 9, 2021
# [40.2.0](v40.1.0...v40.2.0) (2021-12-09)

### Bug Fixes

* **partition:** linkLabel textColor override ([#1498](#1498)) ([3013310](3013310))
* **waffle:** use descend sortPredicate by default ([#1510](#1510)) ([763e2e3](763e2e3))
* **xy:** stacked polarity ([#1502](#1502)) ([920666a](920666a)), closes [#1280](#1280)

### Features

* **xy:** expose style for interpolation fit functions ([#1505](#1505)) ([3071457](3071457))
nickofthyme added a commit to nickofthyme/elastic-charts that referenced this issue Dec 9, 2021
Resolves issue with stacking a mix of negative and positive bars and areas for any `StackMode`. Key changes include:

- Disallowing stacked band charts (i.e. using `stackAccessors` with `y0Accessors`). Now shows `console.warn` when used and ignores `y0Accessor` for rendering but still adds to `initialY0` value.
- Blocks showing banded legend and tooltip values for banded stacks, see case above.
- Prevents percentage domain constraining when no `stackAccessors` are specified.

fix elastic#1280
# Conflicts:
#	packages/charts/src/chart_types/xy_chart/rendering/area.ts
nickofthyme added a commit that referenced this issue Dec 9, 2021
Resolves issue with stacking a mix of negative and positive bars and areas for any `StackMode`. Key changes include:

- Disallowing stacked band charts (i.e. using `stackAccessors` with `y0Accessors`). Now shows `console.warn` when used and ignores `y0Accessor` for rendering but still adds to `initialY0` value.
- Blocks showing banded legend and tooltip values for banded stacks, see case above.
- Prevents percentage domain constraining when no `stackAccessors` are specified.

fix #1280
nickofthyme pushed a commit that referenced this issue Dec 9, 2021
## [40.1.1](v40.1.0...v40.1.1) (2021-12-09)

### Bug Fixes

* **partition:** linkLabel textColor override ([#1498](#1498)) ([#1523](#1523)) ([5324c76](5324c76))
* **xy:** stacked polarity ([#1502](#1502)) ([#1522](#1522)) ([bfb853f](bfb853f)), closes [#1280](#1280)
nickofthyme added a commit to nickofthyme/elastic-charts that referenced this issue Dec 10, 2021
Resolves issue with stacking a mix of negative and positive bars and areas for any `StackMode`. Key changes include:

- Disallowing stacked band charts (i.e. using `stackAccessors` with `y0Accessors`). Now shows `console.warn` when used and ignores `y0Accessor` for rendering but still adds to `initialY0` value.
- Blocks showing banded legend and tooltip values for banded stacks, see case above.
- Prevents percentage domain constraining when no `stackAccessors` are specified.

fix elastic#1280
# Conflicts:
#	integration/tests/__image_snapshots__/axis-stories-test-ts-axis-stories-should-switch-to-a-30-minute-raster-1-snap.png
#	packages/charts/src/chart_types/xy_chart/rendering/area.ts
#	packages/charts/src/chart_types/xy_chart/utils/stacked_series_utils.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working :chart Chart element related issue Impact:High kibana cross issue Has a Kibana issue counterpart :Lens Kibana Lens related issue :xy Bar/Line/Area chart related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants