react-native-chart-kit
react-native-chart-kit copied to clipboard
Line chart full width
Hi im using line chart but i can't make it full width. I checked the element inspector there is no padding so it should be a width problem
You can modify the LineChart.tsx.
Check the point calculation logic here: https://github.com/indiespirit/react-native-chart-kit/blob/f30a37d73cd02807c2f19cd8094f1cacb9f6ba3b/src/line-chart/LineChart.tsx#L677
You need to modify the x calculation logic, the straight way to do is changing the xmax calculations: https://github.com/indiespirit/react-native-chart-kit/blob/f30a37d73cd02807c2f19cd8094f1cacb9f6ba3b/src/line-chart/LineChart.tsx#L651
From:
getXMaxValues = (data: Dataset[]) => {
return data.reduce((acc, cur) => {
return cur.data.length > acc ? cur.data.length : acc;
}, 0);
};
To:
getXMaxValues = (data: Dataset[]) => {
const xmax = data.reduce((acc, cur) => {
return cur.data.length > acc ? cur.data.length : acc;
}, 0);
return Math.max(1, xmax - 1);
};
You can modify the LineChart.tsx.
Check the point calculation logic here:
https://github.com/indiespirit/react-native-chart-kit/blob/f30a37d73cd02807c2f19cd8094f1cacb9f6ba3b/src/line-chart/LineChart.tsx#L677
You need to modify the x calculation logic, the straight way to do is changing the xmax calculations:
https://github.com/indiespirit/react-native-chart-kit/blob/f30a37d73cd02807c2f19cd8094f1cacb9f6ba3b/src/line-chart/LineChart.tsx#L651
From:
getXMaxValues = (data: Dataset[]) => { return data.reduce((acc, cur) => { return cur.data.length > acc ? cur.data.length : acc; }, 0); };
To:
getXMaxValues = (data: Dataset[]) => { const xmax = data.reduce((acc, cur) => { return cur.data.length > acc ? cur.data.length : acc; }, 0); return Math.max(1, xmax - 1); };
@laishere Thank you! Should we open a pull request?
@cs-manughian You're welcome! Feel free to go ahead with the pull request.