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

Cannot adjust padding for inner container

Open designly1 opened this issue 1 year ago • 3 comments

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!

designly1 avatar Jul 12 '24 17:07 designly1

I'm also having same issue.

Anjali111199 avatar Aug 20 '24 10:08 Anjali111199

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,
                  }}

nelsona avatar Aug 21 '24 10:08 nelsona

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?

designly1 avatar Aug 26 '24 21:08 designly1