indiespirit / react-native-chart-kit

📊React Native Chart Kit: Line Chart, Bezier Line Chart, Progress Ring, Bar chart, Pie chart, Contribution graph (heatmap)
https://expo.io/@indiespirit/react-native-chart-kit
MIT License
2.84k stars 656 forks source link

Cannot adjust padding for inner container #732

Open designly1 opened 2 months ago

designly1 commented 2 months ago

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 commented 3 weeks ago

I'm also having same issue.

nelsona commented 3 weeks ago

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 commented 2 weeks ago

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?