Performance issue in realtime continuous plotting of data
- Dominant language
- Swift
- Stars
- 28k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I am using Charts library for my iOS application in which I need to display data plotting with continuous moving of the graph. I am using the below code:
```
var entryAnalog = ChartDataEntry();
let analogLineData = self.analogLineChartVw.lineData ?? LineChartData()
self.analogSet = analogLineData.getDataSetByLabel("Test\(i)", ignorecase: true);
if (self.analogSet == nil) {
self.analogSet = self.createSet(color: UIColor.red, setLabel: "Test\(i)");
entryAnalog = ChartDataEntry(x: 0.6, y: 0)
let isEntryAdded = self.analogSet?.addEntry(entryAnalog);
analogLineData.addDataSet(self.analogSet);
}
else {
let analogIndex = analogLineData.indexOfDataSet(self.analogSet!)
entryAnalog = ChartDataEntry(x: 0.6, y: 0);
analogLineData.addEntry(entryAnalog, dataSetIndex: analogIndex);
}
self.analogLineChartVw.data = analogLineData
self.analogLineChartVw.setVisibleXRangeMaximum(50);
self.analogLineChartVw.moveViewToX(Double(analogLineData.getDataSetByIndex(1)?.entryCount ?? 0));
```
I am receiving data 60ms and the data is in array format of 33 or more.
Currently, I am able to plot the graph and move it continuously. But after 3-4 minutes the graph becomes bulky and it hangs the UI and results in the poor performance of my application.
What I saw in the library charts, on the setting data `self.analogLineChartVw.data = analogLineData` the setter method itself renders the complete UI. So, the continuous calling of this method is re-rendering the whole chart which impacts in the UI performance.
We are also developing similar Android app. We are using [MPAndroidChart](https://github.com/PhilJay/MPAndroidChart) for Android, and following the same process for Android app. But in Android, we are not facing such issue. We observe that in Android, they are using `chart.invalidate()` method, which is missing in this library.
Is there any way we can invalidate the chart view in iOS?
How can I improve the performance of the application so that the it does not blocks the UI?
Contributor guide
Assessment
This issue has not been assessed yet.