Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot adjust padding for inner container #732

Open
designly1 opened this issue Jul 12, 2024 · 3 comments
Open

Cannot adjust padding for inner container #732

designly1 opened this issue Jul 12, 2024 · 3 comments

Comments

@designly1
Copy link

I'm using a custom render on the dots to print the abbreviated value above the dot instead of using a y axis legend. However, the top-most value gets cut off by the upper boundary of the chart's container. I tried adding padding top to both the chart component itself, as well as the chart props. Adding paddingTop to the chart component props does add padding but it's only to the outer container. Adding any styles to the style prop in the chartConfig prop seems to have no effect.
Any help would be greatl appreciated! I created an Expo Snack for your convenience!

https://snack.expo.dev/@devlylabs/chart-example-with-dot-labels

Thanks in advance for any help!

@Anjali111199
Copy link

I'm also having same issue.

@nelsona
Copy link

nelsona commented Aug 21, 2024

To add top padding to the graph containers you will need to make changes to the library code as there are no props exposed that allow you to move the SVG components around in the main SVG container.

For the LineGraph you need to make changes in the node_modules/react-native-chart-kit/dist/line-chart/LineChart.js file as follows:

Change line 379 to:

var legendOffset = this.props.data.legend ? height * 0.15 : chartConfig.yOffset ?? 0;

You will also need to update the node_modules/react-native-chart-kit/dist/AbstractChart.d.ts file and add the following to the AbstractChartConfig:

    yOffset?: number;

You can then use this value in your chartConfig like this:

chartConfig={{
                    ...
                    yOffset: 20,
                  }}

@designly1
Copy link
Author

To add top padding to the graph containers you will need to make changes to the library code as there are no props exposed that allow you to move the SVG components around in the main SVG container.

For the LineGraph you need to make changes in the node_modules/react-native-chart-kit/dist/line-chart/LineChart.js file as follows:

Change line 379 to:

var legendOffset = this.props.data.legend ? height * 0.15 : chartConfig.yOffset ?? 0;

You will also need to update the node_modules/react-native-chart-kit/dist/AbstractChart.d.ts file and add the following to the AbstractChartConfig:

    yOffset?: number;

You can then use this value in your chartConfig like this:

chartConfig={{
                    ...
                    yOffset: 20,
                  }}

Hi, thanks for your suggestion! Looking for a PR on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants