I have a chart with a time-based X axis using IGCategoryDateTimeXAxis. The chart logs data in realtime over the course of about an hour.
I'd like the x-axis labels to only display HH:mm instead of the full datetime, but I can't find a property on the axis that lets me set the date formatter.
I'm using Swift 4.
I found the IGCategoryDateSeriesDataSourceHelper.labelPath property, so I added a label property to my data model object. But setting that doesn't seem to be changing t.
LabelPath is to tell the chart which property or data column the labels are coming from. That's used for category series. What you're looking for is a delegate method on the chart called -chartView: labelForAxis: withInfo. Make sure your view controller is implementing IGChartViewDelegate, though.
-labelForAxis returns a string. It gets called for each label the chart wants to display and here you can change it to anything you want. For x axis, it'll be a date. You can use a date formatter to convert that to your custom format.
You can use info.dataPoint (it'll be an IGCategoryDatePoint) and get a date from that. You can also use info.dataValue, which I believe is your object model and get a date from that, as well.
Ha yep, that's what I was forgetting (did I mention I'm new to iOS?)
So I've got it calling that function now and transforming the label. I'm getting the existing label from info.oldLabel, converting it to a Date object using a DateFormatter using the default format, then converting it back to a String with another DateFormatter using the new format.
Is there a way to get the Date object directly so that I can skip the first step of converting from String to Date? Or is the way I'm doing it correct? Thanks.
Hi, sorry for the late reply.This might be a silly question, but are you setting chartView.delegate to the instance of the class the implements that delegate? That's the most common cause of delegate methods not being called.It doesn't really matter which class implements the delegate, as long as chartView.delegate is set to that.Another possibility is if your chart or delegate class is not retained and goes out of scope.
I can't seem to get this to work. I might be making the wrong view controller the delegate, since none of the delegate methods seem to be being called.
The page that my graph is on has a UIView component on it, which is the frame that the graph is being created in. So the page is created with the empty UIView component (called graphContainer), then at runtime I create the graph object using that graphContainer object as the frame.
I've tried extending the IGChartViewDelegate UIViewController class for the page as well as on the UIView class for the graphContainer, but the delegate methods aren't being called in either of those classes. So I'm not sure which class should be extending the delegate class.