xanderdeseyn / react-native-responsive-linechart

A customizable and responsive line or area chart for react-native
https://react-native-responsive-linechart.surge.sh
MIT License
205 stars 48 forks source link

Bug - Encountered two children with the same key #140

Open LiveXenon opened 2 years ago

LiveXenon commented 2 years ago

Encountered two children with the same key, 1. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

The problem appears when graph contains 2 or more equal y values, example:

        cost exampleData = [
            { x: 10, y: 1 },
            { x: 11, y: 1 }
        ]

Affected platforms: iOS and Android

lukasa1993 commented 2 years ago

any love for this ?

moxie99 commented 10 months ago

Yeah, I had the same error but I was able to get by it mapping through the data supplied to the chart first before passing it to chart helped. More like this :

cost exampleData = [ { x: 10, y: 1 }, { x: 11, y: 1 } ]

const areBidPricesSame = fundData.every((item) => item.y === exampleData[0].y);

if (areBidPricesSame) { return (

All bid prices are the same, cannot render the chart.
);

}

return ( <Chart data={exampleData.map((i, index) => ({ x: index + Math.random(), y: i.y, }))}

>

</Chart>

); };

You can display a table once the y-axis has the same data otherwise the chart is displayed. This won't break your app.