coinjar / react-native-wagmi-charts

A sweet & simple chart library for React Native that will make us feel like We're All Gonna Make It.
MIT License
563 stars 112 forks source link

How to zoom in or out candlestick chart #166

Open tomheo11233aA opened 4 months ago

tomheo11233aA commented 4 months ago

I'm trying to code the zoom-in/out function for CandleStickChart but don't know how to approach it. Can anyone who has done this function help me with this?

honeybadger26 commented 2 months ago

Hi @tomheo11233aA,

One way to achieve this is to change the data that is sent the provider. In this example my original data array has 20 elements and when the button is pressed it is reduced to the first 10 elements and gives the effect of zooming in to that part of the graph:

const [data, setData] = useState([ ... ]); // List of 20 elements

return (
  <>
    <LineChart.Provider data={data}>
      <LineChart>
        <LineChart.Path />
      </LineChart>
    </LineChart.Provider>

    {/* 'Zoom' in to the first half of the chart */}
    <Button onPress={() => setData(data.slice(0, 10))}>Zoom In</Button>

    <Button onPress={() => setData(data)}>Reset</Button>
  </>
);