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

Remove closed market \ gaps in x values

Open natioskar opened this issue 4 years ago • 1 comments

Hello there :) First of all thank you very much for this amazing library your project looks awesome.

I'm having an issue using this library for an other kind of finance data, like stocks that has a time that the market is closed. (unlike crypto currencies 😄 )

For example - How the graph for a stock with closed market period should look like -

CustomChart

how it looks like with react-native-animated-charts (same raw data) -

WithCloseMarket

At the moment is there a way to prevent this behavior? I would really like to work with this lib for it amazing performance improvements over all other charts libraries.

I hope my issue is clear and feel free to ask me for more information Thanks

natioskar avatar Feb 08 '21 21:02 natioskar

hi man, you can try to generate the X as index itself, because this ChartPath logic are calculating width value from X data.

if you're using X value based on the array index itself, you'll get consistent chart graph.

here's an example of my implementation :

 let convertedChartData: ChartDataModel = [];
        let convertedChartXData: ChartXDataModel = [];
        const historicalData = response?.data.data;
        if ((historicalData?.length ?? 0) > 0) {
          historicalData?.forEach((item, index) => {
            const closingPrice = item.c ? item.c : 0;
            convertedChartData.push({
              x: index,
              y: closingPrice * idrCurrencyRate,
            });
            convertedChartXData.push({
              x: (item.t ?? 0) * 1000,
            });
          });
        }

as you can see i have 2 variables to store the chart, 1 (convertedChartData) is used for populating the chart, the other one (convertedChartXData) this one will be used for our ChartInfo to display the correct date based on user selected index.

hope it helps :)

rinoarmadiaz avatar Aug 31 '21 11:08 rinoarmadiaz