Skip to content

Option to prevent non-zero bar chart values from vanishing #4604

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

Closed
miqh opened this issue Feb 26, 2020 · 3 comments
Closed

Option to prevent non-zero bar chart values from vanishing #4604

miqh opened this issue Feb 26, 2020 · 3 comments

Comments

@miqh
Copy link
Contributor

miqh commented Feb 26, 2020

Hello,

When using the bar chart, I noticed if the difference between the smallest and largest values is large enough then the bars corresponding to small values completely vanish. I haven't probed too deeply into the bar chart implementation, but I'm guessing this has to do with how the combination of the value scale and available pixels to plot the bar chart essentially erases insignificant bar chart values.

In my particular use case, it's crucial that any non-zero bar chart values remain visually apparent (e.g. single pixel height bar) because the apparent absence might mislead users into thinking that a data point has no value at all.

I haven't been able to find any bar chart configuration properties that might help me with this either. Is this an option that can be introduced? Or perhaps there's a workaround I'm unaware of?

An example to demonstrate this effect:

<!DOCTYPE html>
<html>
  <head>
    <title>Plotly.js Example</title>
    <meta charset="UTF-8" />
  </head>
  <body>
    <button id="button">Increase Last Value</button>
    <div id="plot"></div>
    <script src="src/index.js"></script>
  </body>
</html>
import Plotly from "plotly.js";

const data = [
  {
    y: [0, 1, 2, 3, 100, 10000],
    type: "bar"
  }
];

const plot = document.getElementById("plot");
const button = document.getElementById("button");

Plotly.newPlot(plot, data);

button.addEventListener("click", () => {
  data[0].y[data[0].y.length - 1] *= 10;
  Plotly.newPlot(plot, data);
});

Here's a CodeSandbox setup with the above.

#2941 seems to express a somewhat similar request. However, in my case, I make no distinction between 0 and null—I'd view both as "zero" bar chart values.

@archmoj
Copy link
Contributor

archmoj commented Feb 26, 2020

Thanks for using plotly.
You could set marker.line.width similar to this demo.
For questions like this in future we appreciate if you use the community website at https://community.plot.ly

@archmoj archmoj closed this as completed Feb 26, 2020
@miqh
Copy link
Contributor Author

miqh commented Feb 26, 2020

@archmoj, thanks for setting up that demo, but it wasn't exactly what I was after.

In the demo, every bar chart value (even zero) has a visible bar height. I specifically indicated that in the latter case, it's desirable to have no visual indication of a bar.

However, I can still see a workaround for my case from your suggestion since you've opted to close the issue.

For anybody else landing on this issue in the future, one solution is to use the array form for marker.line.width and to simply map from your actual y values to either 0 or 1 based on whether a y value is non-zero. However, if you also need to deal with negative y values, then this won't work without some additional hackery (i.e. possibly needing to use arbitrary base adjustments).

@archmoj
Copy link
Contributor

archmoj commented Feb 26, 2020

In the demo, every bar chart value (even zero) has a visible bar height. I specifically indicated that in the latter case, it's desirable to have no visual indication of a bar.

You may also consider passing null instead of zero values similar to this demo.

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

2 participants