Charts icon indicating copy to clipboard operation
Charts copied to clipboard

LineChartView Data rendering problems

Open gag1995 opened this issue 4 years ago • 9 comments

Hello! When I need to render thousands of data, the CPU is too high, causing the app to jam. How can I solve this problem

gag1995 avatar May 25 '20 08:05 gag1995

Me too!!!

beilusen avatar Jul 24 '20 04:07 beilusen

Same here, even for 2000 datapoints the performance is really slow and the app freezes for a few seconds.

Vario avatar Oct 28 '20 14:10 Vario

looking for solution around this as well. I am importing heart rate data from HealthKit, and heart rate is measured very frequently. I can get around this performance issue if i just take one data point from each day, but that doesn't reflect a true trend. Looking for any advice.

chriisong avatar Oct 30 '20 00:10 chriisong

Same here for me! :)

philippjunger avatar Nov 11 '20 16:11 philippjunger

HOW TO SOLUTION???

TimmyLau1991 avatar Nov 17 '20 06:11 TimmyLau1991

So in my case I used IAxisValueFormatter to replace the x-values by Strings. This caused the CPU issues, because the function reloaded the x-axis String values each time I touched the Chart.

Solution for me was to replace my old IAxisValueFormatter function by this one:

// x-Achsen Werte ersetzen final class CustomFormatter: IAxisValueFormatter { var labels: [String] = [] func stringForValue(_ value: Double, axis: AxisBase?) -> String { let count = self.labels.count guard let axis = axis, count > 0 else { return "" } let factor = axis.axisMaximum / Double(count) let index = Int((value / factor).rounded()) if index >= 0 && index < count { return self.labels[index] } return "" } }

philippjunger avatar Nov 17 '20 06:11 philippjunger

@jungerph what was your previous implementation and why is this approach better than the one before?

Vario avatar Nov 18 '20 07:11 Vario

@gag1995 which modes are you using for your datasets? My workaround right now is to use .linear mode where performance is good for large datasets. If you change to any bezier type, then performance is bad

Vario avatar Nov 18 '20 08:11 Vario

The same problem, but with YAxis. Method stringForValue consume too much CPU.

NukleusAcumbens avatar May 23 '23 10:05 NukleusAcumbens