react-native-chart-kit icon indicating copy to clipboard operation
react-native-chart-kit copied to clipboard

Chart fill parent dimension

Open besil opened this issue 6 years ago • 12 comments

Is it possible to make a chart fit the parent component dimension? Without specifying the width or height attribute, the chart crashes (NaN provided).

I'd like to wrap the chart in a Card component, with custom borders and so on, but I don't understand how to correctly wrap it.

Thank you for this great library, it's one of my favourite! S.

besil avatar Aug 25 '19 12:08 besil

@besil Did you manage to get the chart to fill up 100% of the parent container's dimensions?

Tried to set the height props to 100%

<LineChart
    height={'100%'}
/>

but the app throws an error about Invariant Violation containing

"y1":"<<NaN>>"
"y2":"<<NaN>>"

athenawisdoms avatar Aug 25 '19 22:08 athenawisdoms

Hi, I just used

const screenWidth = Dimensions.get('window').width; <PieChart data={...} width={screenWidth}/>

I'd have preferred a 100% option, but it doesn't seem to work

besil avatar Aug 26 '19 12:08 besil

Any updates on this issue?

rishab1065 avatar Oct 15 '19 12:10 rishab1065

Yeah, I have an issue with this too, I need to manually remove padding from all parent containers to make chart not overflow parents.

vedmant avatar Nov 12 '19 17:11 vedmant

Still an issue in 2021.. No one seems to know how to get this working.. My other option might be to somehow get the dimensions of parent View and go from there..

rvkuzmik avatar Apr 29 '21 21:04 rvkuzmik

Any update?

gpessa avatar Jul 05 '21 22:07 gpessa

Any update?

I did it somehow, don't remember how though. When I get back to work tomorrow I can check it out and update this thread.

rvkuzmik avatar Jul 05 '21 22:07 rvkuzmik

You are my hero!

gpessa avatar Jul 05 '21 22:07 gpessa

Any update?

I did it somehow, don't remember how though. When I get back to work tomorrow I can check it out and update this thread.

Are you still at work ? 😆

YanouHD avatar Jul 26 '21 08:07 YanouHD

You can get dimensions of the View component with onLayout(), then set width and height in state and use them in the LineChart.

dawid-jazdzewski avatar Oct 15 '21 07:10 dawid-jazdzewski

See solution by mathcale https://github.com/indiespirit/react-native-chart-kit/issues/506#issuecomment-917564118

Boscotec avatar Oct 10 '22 14:10 Boscotec

See solution by mathcale #506 (comment)

any other solution so far? I've been facing this issue for days 😞

MadelinFg avatar Sep 14 '23 16:09 MadelinFg