Line chart with x axis not working when wrapped in horizontal ScrollView
See original GitHub issueWhat is the problem?
A line chart with an x axis doesn’t render properly when wrapped in a horizontal scroll view.
When does it happen?
I used this example - it was working fine. I wrapped a ScrollView
around it - still good. I added horizontal={true}
to the ScrollView
- the chart breaks.
What platform?
- iOS
- Android
React Native version: 0.55.4
Code to reproduce
import React from 'react'
import { LineChart, XAxis, Grid } from 'react-native-svg-charts'
import { ScrollView, View } from 'react-native'
export default class XAxisExample extends React.PureComponent {
render() {
const data = [50, 10, 40, 95, -4, -24, 85, 91, 35, 53, -53, 24, 50, -20, -80]
return (
<ScrollView horizontal={true}>
<View style={{ height: 200, padding: 20 }}>
<LineChart
style={{ flex: 1 }}
data={data}
gridMin={0}
contentInset={{ top: 10, bottom: 10 }}
svg={{ stroke: 'rgb(134, 65, 244)' }}
>
<Grid />
</LineChart>
<XAxis
style={{ marginHorizontal: -10 }}
data={data}
formatLabel={(value, index) => index}
contentInset={{ left: 10, right: 10 }}
svg={{ fontSize: 10, fill: 'black' }}
/>
</View>
</ScrollView>
)
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to scroll horizontal in a line chart using fl_chart in Flutter?
Edit: I think you need to wrap the LineChart() in a Container() with fixed width first. Otherwise the Chart may try to extend...
Read more >X Axis scrolling | Power BI Exchange
Hello, In the attached Stacked column chart , the X Axis doesn't display all the years, it allows scrolling .
Read more >ScrollView - React Native
Component that wraps platform ScrollView while providing integration with touch locking "responder" system.
Read more >JavaScript Chart Common Axis Settings – Label - DevExtreme
Unless the rotated property is set to true, the argument axis is horizontal and the value axis is vertical. This property accepts one...
Read more >Taming React Native's ScrollView with flex | by Peter Piekarczyk
It will apply styles to the content container as if there were a View wrapping your children. It worked great on the iPhone...
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 FreeTop 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
Top GitHub Comments
Hi! You don’t have any
width
set (andflex:1
doesn’t work in the context of a ScrollView). Always try your layouts with justView
s to make sure that it’s correct before adding more complex componentsYeah, It’s works!