{"action":"opened","issue":{"url":"https://api.github.com/repos/danielgindi/ios-charts/issues/754","repository_url":"https://api.github.com/repos/danielgindi/ios-charts","labels_url":"https://api.github.com/repos/danielgindi/ios-charts/issues/754/labels{/name}","comments_url":"https://api.github.com/repos/danielgindi/ios-charts/issues/754/comments","events_url":"https://api.github.com/repos/danielgindi/ios-charts/issues/754/events","html_url":"https://github.com/danielgindi/ios-charts/issues/754","id":133281768,"number":754,"title":"Live data ","user":{"login":"AdamMak","id":17201601,"avatar_url":"https://avatars.githubusercontent.com/u/17201601?v=3","gravatar_id":"","url":"https://api.github.com/users/AdamMak","html_url":"https://github.com/AdamMak","followers_url":"https://api.github.com/users/AdamMak/followers","following_url":"https://api.github.com/users/AdamMak/following{/other_user}","gists_url":"https://api.github.com/users/AdamMak/gists{/gist_id}","starred_url":"https://api.github.com/users/AdamMak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdamMak/subscriptions","organizations_url":"https://api.github.com/users/AdamMak/orgs","repos_url":"https://api.github.com/users/AdamMak/repos","events_url":"https://api.github.com/users/AdamMak/events{/privacy}","received_events_url":"https://api.github.com/users/AdamMak/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-12T16:21:48Z","updated_at":"2016-02-12T16:21:48Z","closed_at":null,"body":"I am looking to create a graph that will plot live data onto a line chart, need to plot around 5 a second, I am trying to create something like this\r\n\r\nhttp://www.highcharts.com/demo/dynamic-update\r\n\r\nI have had some moderate success with the Line Chart, but it is very jerky. The code I have tried so far looks like this\r\n\r\n@IBOutlet weak var chartView: LineChartView!\r\n    var xAxisArray : [String]?\r\n    var yAxisArray : [Double]?\r\n    var date : NSDate?\r\n    var dateFormatter : NSDateFormatter?\r\n    \r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \r\n        self.title = \"Live Graph\"\r\n        \r\n        let stringArray = NSMutableArray()\r\n        let numberArray = NSMutableArray()\r\n        \r\n        dateFormatter = NSDateFormatter()\r\n        dateFormatter!.dateFormat = \"HH:mm:ss\"\r\n        date = NSDate()\r\n      \r\n        //Insert random values into chart\r\n        for(var i = 0; i < 40; i++)\r\n        {\r\n            date = date!.dateByAddingTimeInterval(0.3)\r\n            let stringDate = dateFormatter?.stringFromDate(date!)\r\n            stringArray.addObject(stringDate!)\r\n            let randomNum = self.randomBetweenNumbers(0.005, secondNum: 0.015)\r\n            numberArray.addObject(randomNum)\r\n        }\r\n        \r\n        xAxisArray = stringArray as NSArray as? [String]\r\n        yAxisArray = numberArray as NSArray as? [Double]\r\n\r\n        configureChart()\r\n        setData()\r\n        \r\n        NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: \"updateChart\", userInfo: nil, repeats: true)\r\n    }\r\n    \r\n    func configureChart()\r\n    {\r\n        //Chart config\r\n        chartView.descriptionText = \"\"\r\n        chartView.noDataTextDescription = \"Add Data\"\r\n        chartView.drawGridBackgroundEnabled = false\r\n        chartView.dragEnabled = true\r\n        chartView.rightAxis.enabled = false\r\n        chartView.doubleTapToZoomEnabled = false\r\n        chartView.legend.enabled = false\r\n        \r\n        //Configure xAxis\r\n        let chartXAxis = chartView.xAxis as ChartXAxis\r\n        chartXAxis.labelPosition = .Bottom\r\n        chartXAxis.setLabelsToSkip(5)\r\n        \r\n        //configure yAxis\r\n        chartView.zoom(1.0, scaleY: 1.0, x: 0.0, y: 0.0)\r\n    }\r\n    \r\n    func randomBetweenNumbers(firstNum: CGFloat, secondNum: CGFloat) -> CGFloat{\r\n        return CGFloat(arc4random()) / CGFloat(UINT32_MAX) * abs(firstNum - secondNum) + min(firstNum, secondNum)\r\n    }\r\n    \r\n    func randomDoubles(firstNum : Double, secondNum : Double) ->Double\r\n    {\r\n        return Double(arc4random()) / Double(UINT32_MAX) * abs(firstNum - secondNum) + min(firstNum, secondNum)\r\n    }\r\n    \r\n    func updateChart()\r\n    {\r\n        let mutableArray = NSMutableArray()\r\n        for(var i = 1; i < xAxisArray?.count; i++)\r\n        {\r\n            mutableArray.addObject(xAxisArray![i])\r\n        }\r\n\r\n        date = date!.dateByAddingTimeInterval(1.0)\r\n        let str = dateFormatter!.stringFromDate(date!)\r\n        mutableArray.addObject(str)\r\n        \r\n        xAxisArray = mutableArray as NSArray as? [String]\r\n        \r\n        //Numbers\r\n        let numberArray = NSMutableArray()\r\n        for(var i = 1; i < yAxisArray?.count; i++)\r\n        {\r\n            numberArray.addObject(yAxisArray![i])\r\n        }\r\n\r\n        let randomNum = self.randomBetweenNumbers(0.005, secondNum: 0.015)\r\n        let convertToDouble = Double(randomNum)\r\n        \r\n        numberArray.addObject(convertToDouble)\r\n        \r\n        yAxisArray = numberArray as NSArray as? [Double]\r\n        \r\n        setData()\r\n\r\n    }\r\n    \r\n    func setData()\r\n    {\r\n        // 1 - creating an array of data entries\r\n        var yVals1 : [ChartDataEntry] = [ChartDataEntry]()\r\n        for var i = 0; i < xAxisArray!.count; i++ {\r\n            yVals1.append(ChartDataEntry(value: yAxisArray![i], xIndex: i))\r\n        }\r\n        \r\n        // 2 - create a data set with our array\r\n        let set1: LineChartDataSet = LineChartDataSet(yVals: yVals1, label: \"\")\r\n        \r\n        set1.axisDependency = .Left // Line will correlate with left axis values\r\n        set1.setColor(UIColor.blueColor().colorWithAlphaComponent(0.5)) // our line's opacity is 50%\r\n        set1.setCircleColor(UIColor.blueColor()) // our circle will be dark red\r\n        set1.lineWidth = 2.0\r\n        set1.circleRadius = 6.0 // the radius of the node circle\r\n        set1.fillAlpha = 65 / 255.0\r\n        set1.fillColor = UIColor.blueColor()\r\n        set1.highlightColor = UIColor.whiteColor()\r\n        set1.drawCircleHoleEnabled = true\r\n        set1.drawFilledEnabled = true\r\n        \r\n        //3 - create an array to store our LineChartDataSets\r\n        var dataSets : [LineChartDataSet] = [LineChartDataSet]()\r\n        dataSets.append(set1)\r\n        \r\n        //4 - pass our months in for our x-axis label value along with our dataSets\r\n        let data: LineChartData = LineChartData(xVals: xAxisArray, dataSets: dataSets)\r\n\r\n        //5 - finally set our data\r\n        self.chartView.data = data\r\n        \r\n        //Clear text color\r\n        chartView.data?.setValueTextColor(UIColor.clearColor())\r\n    }\r\n\r\nI would like to have the x axis scroll similar to the example shown above. Is there a way to do this with iOS charts at present? Or is the charting framework not really made for live data charts like this?\r\n\r\nAny help would be much appreciated\r\n"}}