Conditionally skip a bar
See original GitHub issueI 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:
- Created 5 years ago
- Reactions:4
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tried approach with custom shape for each
Bar
and manually generatingpath
for eachBar
depending on the payload it gets. Came up with theConditionalRectangleBar
that will have 0 width when no specific key is present and normalRectangeBar
which will adjust it’s position onAxisX
whenever first conditionalBar
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 😄
You can use the
hide
attribute on theBar
component. Unfortunately it’s not mentioned in the documentation, I got it from exploring the source code.