React-native-chart-kit: setting min & max ranges for line charts

Created on 3 Dec 2020  Â·  7Comments  Â·  Source: indiespirit/react-native-chart-kit

Is it possible to set the min & max which are not from the data itself?

Sat my data is [20,30] and I would still like to see the Y axis from 10-80. Is it possible?

If not I believe it would be great to add it.

Would be happy to add it myself

Most helpful comment

I used this datasets: [ { data, }, { data: [min, max], color: () => 'transparent', strokeWidth: 0, withDots: false, }, ],

All 7 comments

As a hack i set a 2nd dataset with desired [min, max] and render a transparent line. Not ideal but worked as a temp fix for me.

Thanks !

On Mon, Feb 22, 2021, 20:04 Geoff Abbott notifications@github.com wrote:

As a hack i set a 2nd dataset with desired [min, max] and render a
transparent line. Not ideal but worked as a temp fix for me.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/indiespirit/react-native-chart-kit/issues/447#issuecomment-783561969,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AO6CAQRVBBCJGKRPMPODZQDTAKMBTANCNFSM4UMDDR2A
.

Good method!

As a hack i set a 2nd dataset with desired [min, max] and render a transparent line. Not ideal but worked as a temp fix for me.

Nice hack! Any way to set withShadow={false} just for that hacky line?

I used this datasets: [ { data, }, { data: [min, max], color: () => 'transparent', strokeWidth: 0, withDots: false, }, ],

@BishoyBishai This worked thank you!

As a hack i set a 2nd dataset with desired [min, max] and render a transparent line. Not ideal but worked as a temp fix for me.

Nice hack! Any way to set withShadow={false} just for that hacky line?

The method @BishoyBishai proposed causes the single data point to get rendered halfway through the chart, which gives that shadow. The way to hide it is to fill the whole length of your data with the min, max:

// this assumes that all datasets[i].data are the same length and that datasets[0].data is defined
datasets: [
  ...datasets,
  {
    data: new Array(datasets[0].data.length).fill(min),
    color: () => 'transparent',
    strokeWidth: 0,
    withDots: false,
  },
  {
    data: new Array(datasets[0].data.length).fill(max),
    color: () => 'transparent',
    strokeWidth: 0,
    withDots: false,
  },
],
Was this page helpful?
0 / 5 - 0 ratings

Related issues

vedika96 picture vedika96  Â·  4Comments

Ivanrs297 picture Ivanrs297  Â·  6Comments

NS-BOBBY-C picture NS-BOBBY-C  Â·  5Comments

LillyBrainy picture LillyBrainy  Â·  4Comments

Danjavia picture Danjavia  Â·  5Comments