I need advice on the most performant setup for a IGChartView with a line series. It's really basic, but I'm second guessing the previous designs that I've used because maybe something new has been released in the interim. Here are my realm objects:
class RecordingRow: Object {
dynamic var createdOn:NSDate = NSDate()
let measurements = List<Measurement>()
}
class Measurement: Object {
dynamic var value:Double?
Hi,
This should be pretty straight forward with the category line series and a datasource helper. Your options for empty values are to either interpolate between two known values or create breaks in your line. This is done with unknownValuePlotting property of the IGLineSeries. I'm not sure exactly what you plan on doing with the optional values, but if you just want to omit them, you can use the entire column of your data in the datasource helper. By default the category labels get pre-calculated, but you can turn that off by setting autoGenerateLabels to false on your datasource helper and instead use a delegate method off IGChartViewDelegate:
optional public func chartView(chartView: IGChartView, labelForAxis axis: IGAxis, withItem item: NSObject, oldLabel: String) -> String
Which data source helper? How about rolling my own?
What does autoGenerateLabels do, exactly?
How do I know what x-xvalue (timestamp) I'm dealing with using the delegate method chartView:labelForAxis:withItem? The best I can surmise is encoding the unix timestamp as a string and then formatting it on-demand in the aforementioned delegate method.
You can use the built-in IGCategorySeriesDataSourceHelper or roll your own. I think this scenario should be simple enough to use the existing helper.
DataSource helpers create internal data points for the chart view to use, so by default the category helper builds out an array of data points with value and label pairs. When you have lots of data points, those label strings can temporarily take out a large chunk of memory. When you set autoGenerateLabels to false, it's as if you're not supplying any labels to the chart. This speeds up the initial rendering of the chart, but also forces you to supply labels for the data points (only the visible ones) at run time through a delegate method
What I typically do is get an index of the visible point that wants the label and fetch a string that presumably already exists either locally or in a database.
func chartView(chartView: IGChartView, labelForAxis axis: IGAxis, withItem item: NSObject, oldLabel: String) -> String {
if (axis is IGCategoryXAxis){
let index = _myLineSeries.dataPoints.indexOfObject(item)
return _myStrings[index] as! String
return oldLabel
OK. For what it's worth, indexOfObject: isn't ideal. It would be nice if the delegate call had the index, or if the "item" conformed to a protocol that offered an index property.
Sure, we can add the index to the delegate method in some way. That should be trivial.