Abhinandan-Kushwaha / react-native-gifted-charts

The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.
https://www.npmjs.com/package/react-native-gifted-charts
MIT License
763 stars 151 forks source link

Dataset changes but line chart not rerender reflect to new dataset change (2)? #732

Open dumihi313 opened 2 months ago

dumihi313 commented 2 months ago

https://github.com/user-attachments/assets/f32dc06a-9765-4764-9600-76b9651699f4

To continue with issue

When I change the dataset, it just rerenders for datapoints. It doesn't rerender to remove old line and add new line based on dataset

dumihi313 commented 2 months ago

this my code, I overcame by update a new timestamp to key prop (force rerender). Is there any better solution than this?

` useEffect(() => {

  if (batteryChart && batteryChart.length > 0) {
    const result = parseDTOtoChartModel(
      batteryChart,
      renderDataPointLabelComponent,
    ).dataSet
    setDataSet(result)
    savedDataSet.current = result.map(a => Object.assign({}, a))
    setRenderChartWithDateKey(date) // force rerender
  } else if (batteryChart) {
    setDataSet(emptyChart24hDataset)
    savedDataSet.current = emptyChart24hDataset.map(a =>
      Object.assign({}, a),
    )
    setRenderChartWithDateKey(date) // force rerender
  }

}, [batteryChart])`