I need to create a chart in react native that takes data (Array of integer) from a native module every 500 m/s and plots them in live update, to do this I used "react-native-svg", I can actually update the chart but performance is very slow and and crashes are frequent.
Array of result accept a maximum of 1800 results, after which the graph scrolls
...
const [data, setData] = useState(new Array(1800).fill(0));
...
In listener take data from native module and update array, from the native module I pass an array of 60 elements, since it takes 60 elements every 500 m/s (e.values is the array of 60 integers)
...
setData(state => {
state.splice(0, 60)
return [...state, ...e.values]
})
...
The chart
...
<LineChart
style={ { flex: 1 } }
data={data.map(dt => {
return dt
})}
svg={ {
strokeWidth: 2,
stroke: '#2171bf',
} }
yMin={-5000}
yMax={10000}
numberOfTicks={25}
>
<CustomGrid belowChart={true} />
</LineChart>
...
I tried other charts libs but they all give the same result
P.S. Sorry if the language is not perfect.