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.

Line chart with x axis not working when wrapped in horizontal ScrollView

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
JesperLeklandcommented, Jun 18, 2018

Hi! You don’t have any width set (and flex:1 doesn’t work in the context of a ScrollView). Always try your layouts with just Views to make sure that it’s correct before adding more complex components

0reactions
ThoMiDevcommented, Oct 4, 2019

Yeah, It’s works!

Read more comments on GitHub >

github_iconTop 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 >

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