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.

Chart disappears on second time navigating to screen

See original GitHub issue

Hey all,

Pretty basic chart setup (see code below). Works great on first time navigating to screen, but if I pop back and then navigate to the screen again, the chart path disappears (dot still works though!) Using latest react-navigation if that helps.

Thanks!

<ChartPathProvider data={{ points: data }}>
    <ChartPath
        {...{ width }}
        fill='none'
        height={width / 2}
        stroke='black'
        strokeWidth={3.5}
        selectedStrokeWidth={3}
    />
    <ChartDot size={16} style={styles.chartDot} />
</ChartPathProvider>

https://user-images.githubusercontent.com/2816603/103932089-2e9a0000-50d6-11eb-8a60-7f8deaf1bf22.mov

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
mattfrancescommented, Jul 13, 2021

Workaround solution Add a setTimeout to the useEffect of the component rendering the Chart to toggle the chart visible after a delay of 0:

const [chartVisible, setChartVisible] = useState(false);
useEffect(() => {
  setTimeout(() => {
    setChartVisible(true);
  }, 0);
}, [data]);

...

{chartVisible ? (
  <>
    <ChartPath ... />
    <ChartDot ... />
  </>
) : null}

Explanation I’m not exactly sure why this works, but here’s my best guess: The ChartPath file has 2 variables that keep track of the previous data and the current data (prevData & currData). When navigating back to a screen, the previous and current data need to be updated to reflect the chart that should be showing. The problem is that there is a slight delay in the code to update these values, and the ChartPath ends up being rendered before the data is ready, leading to the empty line seen in the screen recordings above.

My understanding and the explanation above is not complete, so if @osdnk or @outaTiME have more context that would be really appreciated 🙌

0reactions
kierangillencommented, Oct 24, 2022

I’ve noticed weird rendering behavior when the ChartPath and the ChartDot are not located in the component where the ChartPathProvider is. I believe the issue is that React isn’t properly updating the render of the children when the points are updated in the provider because the path and dots aren’t receiving direct state updates. Try keeping the dot and path in the same component as the provider and see if it helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Charts flash quickly and then disappear when navigating back ...
Go back to plunker tab and resize browser's window once again; Chart is gone; Switch to another tab and go back to plunker...
Read more >
Chart disappears just after finishing animation - Stack Overflow
The Chart appears at first, but when first animation ends it disappears. Javascript console shows nothing. And when a option animation is defined...
Read more >
Series chart disappears after Save, reappears when Insert 2D ...
I have 3 charts, each being 2D Line Charts based on Series data. ... it is not unusual for the chart to disappear...
Read more >
How to Keep the Chart Size Consistent While Changing ...
How to Keep the Chart Size Consistent While Changing Screen Size in ... elements side by side or two charts side by side...
Read more >
Excel Charts - three methods for filtering Chart Data - YouTube
Filtering data in Excel charts is easy to do. ... data and how to keep a chart from moving or disappearing when you...
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