react-native-gifted-charts icon indicating copy to clipboard operation
react-native-gifted-charts copied to clipboard

Multicolor line chart

Open aljazkosirnik opened this issue 2 years ago • 1 comments

Hey, I am wondering if it's possible to create a multicolor line chart? Something like this:

image

I saw you are limited with your time, I can try to create the PR myself if you can guide me to the right component and quickly describe how you would implement this :)

aljazkosirnik avatar Jul 14 '22 16:07 aljazkosirnik

I would like to implement the same behavior on my chart aswell Let me know if you have news.

I can help on the PR

darkholiday avatar Sep 27 '22 10:09 darkholiday

Hi @darkholiday @aljazkosirnik 👋 Thanks for requesting this feature. It is now available in version 1.3.14🎉

It can be achieved using the some or all of the following props-

lineGradient?: boolean;
lineGradientComponent?: () => any;
lineGradientId?: string;
lineGradientDirection?: string;
lineGradientStartColor?: string;
lineGradientEndColor?: string;

Minimal example to show multicolor line chart-

<LineChart
    data={lineData}
    spacing={10}
    hideDataPoints
    lineGradient
/>

The output is-

Screenshot 2023-11-02 at 12 29 27 AM

Notice that the line gets a gradient of lightgreen and orange color by default. These can be customised using the lineGradientStartColor and lineGradientEndColor props respectively.

We can use our own gradient component via the lineGradientComponent prop. Note that lineGradient prop is mandatory when using custom gradient component.

Here's an example of custom lineGradientComponent-

LineChart
  data={lineData}
  spacing={10}
  hideDataPoints
  lineGradient
  lineGradientId="ggrd"
  lineGradientComponent={() => {
    return (
      <LinearGradient id="ggrd" x1="0" y1="0" x2={'0'} y2={'1'}>
        <Stop offset="0" stopColor={'blue'} />
        <Stop offset="0.5" stopColor={'orange'} />
        <Stop offset="1" stopColor={'green'} />
      </LinearGradient>
    );
  }}
/>

The output is-

Screenshot 2023-11-02 at 12 36 15 AM

Abhinandan-Kushwaha avatar Nov 01 '23 19:11 Abhinandan-Kushwaha