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

Line chart full width

Open cagataysayg opened this issue 1 year ago • 3 comments

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

IMG_1331

cagataysayg avatar Oct 20 '23 12:10 cagataysayg

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 avatar Feb 10 '24 00:02 laishere

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 avatar May 30 '24 23:05 cs-manughian

@cs-manughian You're welcome! Feel free to go ahead with the pull request.

laishere avatar Jun 02 '24 15:06 laishere