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.

TypeScript Error when putting Chart inside of ResponsiveContainer

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

Put a Chart inside of a ResponsiveContainer - see also codesandbox

–> TypeScript Error in ChartUtils.js:86 at calculateActiveTickIndex

What is expected?

No Error

What is actually happening?

I really cant tell because i am new to recharts. I tried with version 2.0.0, 2.0.1 and 2.0.2 I cant even run the examle codes provided on recharts.org inside of a ResponsiveContainer I get a TypeError: Cannot read property ‘length’ of undefined

Environment Info
Recharts v2.0.2
React tested with 16.14 and 17.0.0
System Windows 10
Browser Chrome

I made a very short codesandbox to reproduce: https://codesandbox.io/s/recharts-typescript-error-4mtpq

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
marnixhohcommented, Jan 16, 2021

I am having the same issue as @raRaRa. The error appears to be coming from calculateActiveTickIndex

Note: for me it only appears in my Jest tests when after the component has mounted I change what is being passed to data (BarChart) using setProps(). Whether or not the contents of the array change doesn’t seem to matter. Instead, it seems that an error is thrown when the reference to the array is changed (a new array is passed to the data prop).

It appears that this results in the ticks passed to calculateActiveTickIndex to be undefined, leading to the error as pointed out by @raRaRa. Note that my tests used to pass on Recharts version 1.8.5. It stopped working after upgrading to 2.0.3.

Also, I have tried it without the ResponsiveContainer, but the error persists…

React: 16.14.0

0reactions
ferdinglercommented, Jan 19, 2021

+1, removing <ResponsiveContainer> doesn’t change anything. The issue still appears in our Jest tests

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recharts Responsive Container does not resize correctly ...
Clarification: The problem is that when I close and then open the legend, the legend component gets pushed out of the viewing area...
Read more >
Recharts
Quickly build your charts with decoupled, reusable React components. Reliable. Built on top of SVG elements with a lightweight dependency on D3 submodules....
Read more >
CHANGELOG.md · Gitee 极速下载/recharts - Gitee.com
Allowing length in different unit in ResponsiveContainer By allowing type: String on 'minHeight', 'minWidth', 'maxHeight' property, developers can use length in ...
Read more >
recharts | Yarn - Package Manager
Recharts is a Redefined chart library built with React and D3. The main purpose of this library is to help you to write...
Read more >
Build and Custom Style Recharts Data Charts
We'll get into this more when we create the tooltip component, so put a pin in this for now. ResponsiveContainer wraps the whole...
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