Chart disappears on second time navigating to screen
See original GitHub issueHey 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:
- Created 3 years ago
- Reactions:7
- Comments:16 (3 by maintainers)
Top 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 >
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 Free
Top 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
Workaround solution Add a
setTimeout
to theuseEffect
of the component rendering the Chart to toggle the chart visible after a delay of 0: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 theChartPath
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 🙌
I’ve noticed weird rendering behavior when the
ChartPath
and theChartDot
are not located in the component where theChartPathProvider
is. I believe the issue is that React isn’t properly updating the render of the children when thepoints
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.