React-native-chart-kit: How can I remove margin on the left on LineChart or any other ? 馃

Created on 8 Apr 2021  路  7Comments  路  Source: indiespirit/react-native-chart-kit

I tried to fix this issue with any props from the library (propsForHorizontalLabels, chartConfig, etc.) but didn`t found any solution. So do you have a quick solution for this or it can be fixed only by modifying the library properly?

P.S. Great library, but there are some restrictions for building graphics =)

Screenshot-2021-04-08-at-13-26-49
Screenshot-2021-04-08-at-13-27-25

Most helpful comment

Default styling seems to be set to the following in the line chart component specifically:

paddingTop = 16
paddingRight = 64

Adjusting styles on the line chart fixed the width and height issues I was dealing with.

style={{
    paddingTop: 0,
    paddingRight: 0,
}}

All 7 comments

Very interesting in this subject too

This is a library issue.. i used a temporary solution
i disabled both labels
withVerticalLabels={false}
withHorizontalLabels={false}

and
in style component povided marginhorizontal: -16 (or whatever you want)
did the trick for me
hope it's any help

I have same problem

@Mirzatalha
data={data}
width={screenWidth-20}
height={220}
chartConfig={chartConfig}
withVerticalLines={false}
withHorizontalLines={false}
withVerticalLabels={false}
withHorizontalLabels={false}
// onDataPointClick={({ value, getColor }) =>
// Alert.alert("Details",${value})}
style={{
marginhorizontal: -16
}}
withDots={false}
// bezier
/>

const chartConfig = {
backgroundColor: CardBackGroundColor,
backgroundGradientFrom: CardBackGroundColor,
backgroundGradientTo: CardBackGroundColor,
backgroundGradientFromOpacity: 1,
backgroundGradientToOpacity: 1,
color: (opacity = 1) => rgba(255, 255, 255, ${opacity}),
labelColor: (opacity = 1) => rgba(255, 255, 255, ${opacity}),
barPercentage: 1,
// useShadowColorFromDataset:false, // optional
style: {
marginhorizontal:-16
},
};

Not Working

@imransiddiquiandroid

                    <LineChart
                        data={{whatever your data is
                        }}
                        withInnerLines={false}
                        withOuterLines={false}
                        withVerticalLines={true}
                        withVerticalLabels={false}
                        withHorizontalLabels={false}
                        width={Dimensions.get("window").width} // from react-native
                        height={220}

                        chartConfig={{
                            backgroundColor: "white",
                            backgroundGradientFrom: "#fff",
                            backgroundGradientTo: "#fff",
                            decimalPlaces: 2, // optional, defaults to 2dp
                            color: (opacity = 1) => `rgb(45, 45, 98,${opacity})`,
                            labelColor: (opacity = 1) => `rgb(45, 45, 98, ${opacity})`,
                            style: {
                                borderRadius: 16,
                            },
                            propsForDots: {
                                r: "7",
                                strokeWidth: "0",
                                stroke: "white"
                            }
                        }}
                        bezier
                        style={{
                            marginVertical: 18,
                            marginHorizontal: -20, //You can style here
                            borderRadius: 16
                        }}
                    />

@imransiddiquiandroid

                    <LineChart
                        data={{whatever your data is
                        }}
                        withInnerLines={false}
                        withOuterLines={false}
                        withVerticalLines={true}
                        withVerticalLabels={false}
                        withHorizontalLabels={false}
                        width={Dimensions.get("window").width} // from react-native
                        height={220}

                        chartConfig={{
                            backgroundColor: "white",
                            backgroundGradientFrom: "#fff",
                            backgroundGradientTo: "#fff",
                            decimalPlaces: 2, // optional, defaults to 2dp
                            color: (opacity = 1) => `rgb(45, 45, 98,${opacity})`,
                            labelColor: (opacity = 1) => `rgb(45, 45, 98, ${opacity})`,
                            style: {
                                borderRadius: 16,
                            },
                            propsForDots: {
                                r: "7",
                                strokeWidth: "0",
                                stroke: "white"
                            }
                        }}
                        bezier
                        style={{
                            marginVertical: 18,
                            marginHorizontal: -20, //You can style here
                            borderRadius: 16
                        }}
                    />

still have same problem

Default styling seems to be set to the following in the line chart component specifically:

paddingTop = 16
paddingRight = 64

Adjusting styles on the line chart fixed the width and height issues I was dealing with.

style={{
    paddingTop: 0,
    paddingRight: 0,
}}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

NS-BOBBY-C picture NS-BOBBY-C  路  5Comments

bailih picture bailih  路  4Comments

Danjavia picture Danjavia  路  5Comments

briaclg picture briaclg  路  4Comments

SyedShahbazHussain picture SyedShahbazHussain  路  4Comments