How does addEntry method update LineChart in real time?
I am using iOS charts to display a simple cube line chart and want to update the graph every second with new messages. I tried using the addEntry method to dynamically add a value to the end of the array, and I verified that the data is indeed successfully added to the array after every second. However, the chart itself is not updated. I looked at the MPAndroidChart documentation and did not set a method to call any update method after the first call to the addEntry method. I see in another section of the documentation that there is an invalidate () method on the Chart object that updates the chart, however I don't have such an option when I access the Chart object and don't know if this is required.
Sample code:
var set1 = lineChartView.data?.getDataSetByIndex(0)
var index = set1?.entryCount
var value = arc4random_uniform(14) + 1
var chartEntry = ChartDataEntry(value: Float(value), xIndex: index!)
set1?.addEntry(chartEntry)
In the demo project, charts are modified using a slider control, but in this example, it just recreates the data and reloads the chart.data object, rather than dynamically modifying the original DataSet as I am trying to do.
Any help on what I need to do or where I need to look is greatly appreciated.
xcode 6.3
swift 1.2
iOS 8.3
iOS-Chart 2.1.0
source to share
try calling notifyDataSetChanged () on your ChartView string, it should update the chart.
Also consider the Known Issues page and in particular this: https://github.com/danielgindi/ios-charts/issues/264 .
source to share