ChartsOrg / ChartsOrg/Charts

line chart cpu usage 95%

Open
#4,095 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

import UIKit
import Charts
class ViewController: UIViewController,IAxisValueFormatter,ChartViewDelegate {


@IBOutlet var chartsVw: LineChartView!
@IBOutlet var lblMessage: UILabel!


var timerForHRValue = Timer()
var startDate : Date?

override func viewDidLoad() {
super.viewDidLoad()

startDate = Date()
//charts
self.chartsVw.delegate = self
let set_a: LineChartDataSet = LineChartDataSet(entries:[ChartDataEntry(x: Double(0), y: Double(0))], label: "voice")
set_a.drawCirclesEnabled = false
set_a.setColor(UIColor.red)
set_a.drawValuesEnabled = false
self.chartsVw.pinchZoomEnabled = false
self.chartsVw.doubleTapToZoomEnabled = false
self.chartsVw.data = LineChartData(dataSets: [set_a])
timerForHRValue = Timer.scheduledTimer(timeInterval: 0.008, target: self, selector: #selector(updateCounter), userInfo: nil, repeats: true)
}

// add point
var i = 1
@objc func updateCounter() {
let number1 = Int.random(in: 0 ... 100)

if (self.chartsVw.data?.entryCount)! > 310 {
self.chartsVw.data?.removeEntry(xValue: 0, dataSetIndex: 0)
}

self.chartsVw.data?.addEntry(ChartDataEntry(x: Double(i), y: Double(number1)), dataSetIndex: 0)
self.chartsVw.setVisibleXRange(minXRange: 1, maxXRange: 300)
self.chartsVw.notifyDataSetChanged()
i = i + 1
}


//MARK: -
func stringForValue(_ value: Double, axis: AxisBase?) -> String {
return ""
}
}

we are plotting data into graph at 8 milisecond. but device cpu usage showing 95%. how to reduce cpu usage.
Plateform : Swift 4.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.