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.

YAxis scale=log not working when any value is 0

See original GitHub issue
  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Create a graph that has values at zero in some field:

const data2 = [
    {
      name: "Page A",
      uv: { value: 200, errors: [100, 200] },
      pv: { value: 2400, errors: [200, 100] }
    },
    {
      name: "Page B",
      uv: { value: 0, errors: [0, 0] }, // change value to something to render
      pv: { value: 4200, errors: [50, 200] }
    },
    {
      name: "Page C",
      uv: { value: 1600, errors: [50, 100] },
      pv: { value: 3200, errors: [100, 100] }
    }
  ];

And try to render with scale=log:

<LineChart
      width={600}
      height={300}
      data={props.data}
      margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
    >
      <XAxis dataKey="name" />
      <YAxis domain={["auto", "auto"]} scale="log" />
      <CartesianGrid strokeDasharray="3 3" />
      <Tooltip />
      <Legend />
      <Line
        type="monotone"
        dataKey="pv.value"
        stroke="#8884d8"
        activeDot={{ r: 8 }}
        connectNulls={false}
      >
        <ErrorBar dataKey={`pv.errors`} width={4} strokeWidth={1.5} />
      </Line>
      <Line
        type="monotone"
        dataKey="uv.value"
        stroke="#82ca9d"
        connectNulls={false}
      >
        <ErrorBar dataKey={`uv.errors`} width={4} strokeWidth={1.5} />
      </Line>{" "}
    </LineChart>

What is expected?

To render the line chart.

What is actually happening?

The line chart is not rendered when scale log and some values at 0. Error in console Warning: Received NaN for the y1 attribute. If this is expected, cast the value to a string. is being printed.

Environment Info
Recharts v2.1.6
React react 16
System any
Browser any

In the example attached you can find one grpah and one not working. The difference: a 0 value in PageB ‘u’ field.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
maycheongscommented, Mar 3, 2022

log(0) being infinity is not a valid argument, as displaying a data in log scale is not logging the values, but the scale itself. I.e. such that the points of your graph are spaced out differently and especially differences in the smaller values are more pronounced. Forgive the drawing image

0reactions
uazurecommented, May 31, 2022

That probably might be helpful as ‘pseudo-log’ solution

I can understand a log scale not displaying 0 values, since log(0) is infinity. So I was trying a workaround through a “pseudo-log” function, but I can’t figure out how to use custom functions with the scale option.

#305 (comment)

Read more comments on GitHub >

github_iconTop Results From Across the Web

D3.js - Log scale starting at zero - Stack Overflow
I am plotting a y axis which should be defined in log scale. The range is from 0 to 1000. If I try,...
Read more >
d3.scale.log(), 0 in domain · Issue #1420 - GitHub
This concerns d3.scale.log() with a value of zero in the domain. When the input domain contain 0 the javascipt-engine will crash, due to...
Read more >
how to set y-axis as log scale? - MATLAB Answers
I used loglog function but it scales both axis but I want only Y. 0 Comments.
Read more >
pandas.DataFrame.plot — pandas 0.22.0 documentation
In case subplots=True, share x axis and set some x axis labels to invisible; defaults to True if ax is None otherwise False...
Read more >
Logarithmic scale - Wikipedia
A logarithmic scale (or log scale) is a way of displaying numerical data over a very wide range of values in a compact...
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