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

[Bug] Stacked bar chart is missing a bar when log scale is used #19517

Closed
kawsndriy opened this issue Jan 16, 2024 · 6 comments
Closed

[Bug] Stacked bar chart is missing a bar when log scale is used #19517

kawsndriy opened this issue Jan 16, 2024 · 6 comments
Labels
en This issue is in English wontfix

Comments

@kawsndriy
Copy link

Version

5.4.3

Link to Minimal Reproduction

https://echarts.apache.org/examples/en/editor.html?code=PYBwLglsB2AEC8sDeAoWsCG0IFsORgC5YAzDAGwGcBTAGjVjGGHMhGKQF970BPAQQAeEShwbowvENWIBycsADmshtwaChIseglSZsWQGN81RcABOvWTx0ATfBmIBtWQDEI5ymGsGAytUMYW1kAXVUbGnMIalFYJ3FkBN1pOQAjDHNrJNgAehzYVIBXRWIwAAtqc2pYSkKQEGAaW0ZgAuryquqqwzAsRXIY2BhGCprDTuhsvNgAeWhyXkYAd1aM6ttzDCXoADps-17nWQBaHwAmAAYrkJsdGt7DAGs5PAhoFTu1O9Q75P1ZdKZW52BzOM4AViutFgAGYrhcbtkvBgni8MG8PjpOAwwpwANxAA

Steps to Reproduce

Use the following configuration:

option = {
  animation: false,
  tooltip: {},
  yAxis: {
    type: 'log' // this is important
  },
  xAxis: {
    type: 'category',
    data: ['First', 'Second']
  },
  series: [
    {
      type: 'bar',
      // bug: there supposed to be three rectangles on the screen
      // Only two are drawn.
      data: ['-', 2000],
      stack: 'main'
    },
    {
      type: 'bar',
      data: [2500, 3000],
      stack: 'main'
    }
  ]
};

Current Behavior

Looks like starting from version 5.3.0 the stacked bar chart with log scale is no longer rendered correctly when one of the stacks has no data marker (-). I

image

Expected Behavior

Expected to see all three bars present.

Environment

- OS: MacOS 13.6.3
- Browser: Chrome Version 120.0.6099.216 
- Framework: plain javascript

Any additional comments?

Looks like the bug was introduced by this commit in the barGrid.ts component - in pre 5.3.0 version the computation accounted for log scale correctly. In 5.3.0+ the log(0) is used to determine the height of the bar, which gives a negative infinity and lack of the rendered rectangle.

@kawsndriy kawsndriy added the bug label Jan 16, 2024
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. labels Jan 16, 2024
@helgasoft
Copy link

see also #19234, #18330, #17960

@Ovilia
Copy link
Contributor

Ovilia commented Jan 17, 2024

See conclusion at #19234. Stacked bars using log axis is misleading and thus this problem is not going to be fixed.

@Ovilia Ovilia closed this as completed Jan 17, 2024
@Ovilia Ovilia added wontfix and removed bug pending We are not sure about whether this is a bug/new feature. labels Jan 17, 2024
@kawsndriy
Copy link
Author

I agree it might be misleading. I'd like to offer a few brief points for reconsideration:

  • Community Interest: There's been notable interest in this feature. Based on number of referenced issues - it meets a specific user need.
  • Correctness: The issue comes with a proposed fix that addresses a very narrow bug, enhancing reliability and trust built with users
  • Other Libraries: Similar functionalities exist in other charting libraries, indicating a recognized utility in certain data visualization contexts.

For example, this matplotlib code allows to render log scaled stacked bars:

import matplotlib.pyplot as plt

categories = ['First', 'Second']
values1 = [1, 2000]
values2 = [2500, 3000]

fig, ax = plt.subplots()
ax.bar(categories, values1, label='Series 1')
ax.bar(categories, values2, bottom=values1, label='Series 2')

# Setting the y-axis to logarithmic scale - ok
ax.set_yscale('log')

plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Stacked Bar Chart with Log Scale')
plt.legend()

# Display the plot
plt.show()

Results in this nice looking image:

image

I hope the Pull request can be accepted as it limits the impact to a very narrow case and address one of our own concerns. Thank you!

@helgasoft
Copy link

Results in this nice looking image

If you like the matplot image, just replace '-' with 1 in the data and you'll get the exact same result
image

@kawsndriy
Copy link
Author

just replace '-' with 1 in the data and you'll get the exact same result

That's essentially what the PR is doing

@helgasoft
Copy link

I think data transformation is a developer's task, it should not be part of any charting library.
Often data has to be modified to meet the needs of the chosen charting library, not the other way around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
en This issue is in English wontfix
Projects
None yet
Development

No branches or pull requests

3 participants