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.

Conditionally skip a bar

See original GitHub issue

I want to conditionally skip rendering a bar in a bar chart. If the data exists, I want to render the bar, but if the data doesn’t exist, I don’t want there to be an empty space in the bar chart.

This is what my chart looks like

<ComposedChart data={data}>
    <Bar dataKey="a"/>
    <Bar dataKey="b"/>
    <Bar dataKey="c"/>
    <Bar dataKey="d"/>
</ComposedChart>

For example, if dataKey “c” is 0 or doesn’t exist, I want to render a, b and d without the empty space that c should occupy.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

3reactions
merio901commented, Aug 21, 2020

I tried approach with custom shape for each Bar and manually generating path for each Bar depending on the payload it gets. Came up with the ConditionalRectangleBar that will have 0 width when no specific key is present and normal RectangeBar which will adjust it’s position on AxisX whenever first conditional Bar is not here.

Here is sandbox, try playing with y key in data array. https://codesandbox.io/s/recharts-conditional-double-bar-chart-7kgze

@bpatterson-r7 @dgarciasarai check this out if this is the outcome you need 😄

3reactions
hossammouradcommented, Mar 11, 2019

You can use the hide attribute on the Bar component. Unfortunately it’s not mentioned in the documentation, I got it from exploring the source code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: If Condition then skip to return
Lets assume the following dummy code: def foo(bar): do(stuff) if condition: do(stuff) if condition2 ...
Read more >
How do you conditionally highlight a bar in a Power BI ...
There are different interactions Power BI visuals can have, but how do we conditionally highlight a bar in a Power BI report using...
Read more >
Conditionally Format Bar Chart - MATLAB Answers
I have a time series bar chart that has positive and negative values, I would like to color code the bars based on...
Read more >
Is there a way to conditionally skip the Playwright Visual ...
Is there a way to conditionally skip the Playwright Visual Comparison toMatchSnapshot() based on if the test is running in headed or ...
Read more >
Conditional Visibility for Utility Bar Components in Lightning ...
Much like the ability to conditionally expose Aura or Lightning Web Components on a Lightning Page, it would be amazing if we could...
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