Search code examples
ioscore-plot

Core Plot Axis Labelling with Time


I am trying to label the X-axis in Core Plot with time values in HH:MM:SS format.Now I want it to start from the current system time everytime. So how do we provide a starting time for the X-axis from where labelling should start.


Solution

  • I achieved it finally by setting the CPTTimeFormatter reference Date parameter to the desired start UTC Time.

    Code Snippet:

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    dateFormatter.dateFormat = @"HH:mm:ss";

    [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];

    CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];

    NSDate *refDate =[NSDate dateWithTimeIntervalSince1970:desiredStartTime];

    timeFormatter.referenceDate = refDate;