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.

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

Edit on CodeSandbox

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:open
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
andy128kcommented, Jul 23, 2021

Ok, here is my brain dump:

When there is a single data point, function getBandSizeOfAxis returns 0 (which is a bug itself). There are scenarios (like mine) when maxBarSize is given, and my patch solves the problem. But there are also scenarios when maxBarSize is undefined and my patch does bad job replacing 0 by undefined.

I see here two possible ways to solve this issue:

  1. replace || by a ??. Here I am not sure if this pretty fresh operator is supported by a recharts’ build tools.
  2. add additional || 0 to the chain.
  3. Revisit the implementation of the function 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.

0reactions
marnixhohcommented, Aug 1, 2021

@andy128k Thank you so much for your suggestion to use maxBarSize. This indeed “solves” the problem for now

Read more comments on GitHub >

github_iconTop 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 >

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