Bar is not showing on a BarChart when there is only one data point after upgrading to 2.0.10 (from 2.0.9)
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Reproduction link
Steps to reproduce
Pass only one data point into the data
prop on the BarChart
component. When multiple are passed everything works as expected.
Note that this did not happen on Recharts 2.0.9. This broke after upgrading to 2.0.10
What is expected?
Bars to show even if there is only one data point.
What is actually happening?
No bars are shown when there is only one data point.
Environment | Info |
---|---|
Recharts | v2.0.8 |
React | 16.14.0 |
System | MacOS |
Browser | Chrome |
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Bar charts in Python
Bar charts with Long Format Data¶. Long-form data has one row per observation, and one column per variable. This is suitable for storing...
Read more >Bar Charts
Like all Google charts, bar charts display tooltips when the user hovers over the data. For a vertical version of this chart, see...
Read more >A Complete Guide to Bar Charts
Bar charts are a fundamental visualization for comparing values between groups of data. Use this guide to learn how to get the most...
Read more >Line chart reference - Looker Studio Help
Line charts can display your data series as either lines, bars, or both. Line charts can plot a single dimension with up to...
Read more >how to set start value as "0" in chartjs?
For Chart.js 2.*, the option for the scale to begin at zero is listed under the configuration options of the linear scale. This...
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
Ok, here is my brain dump:
When there is a single data point, function
getBandSizeOfAxis
returns0
(which is a bug itself). There are scenarios (like mine) whenmaxBarSize
is given, and my patch solves the problem. But there are also scenarios whenmaxBarSize
isundefined
and my patch does bad job replacing0
byundefined
.I see here two possible ways to solve this issue:
||
by a??
. Here I am not sure if this pretty fresh operator is supported by a recharts’ build tools.|| 0
to the chain.getBandSizeOfAxis
and make it return sane results for a single data point.I would like to see a guidance of library maintainers here, which path to chose.
@marnixhoh I suggest you to specify
maxBarSize
property as a temporary workaround.@andy128k Thank you so much for your suggestion to use
maxBarSize
. This indeed “solves” the problem for now