DateTime xAxis question

3 posts, 0 answers
  1. Konstantinos
    Konstantinos avatar
    4 posts
    Member since:
    May 2015

    Posted 13 May 2015 Link to this post

    Hello everyone,

    I'm trying to plot a temperature against time graph that spans across for example the last 24hrs and my xAxis is DateTime with this configuration:

             let xAxis = chart.xAxis as! TKChartDateTimeAxis
            xAxis.style.lineStroke = TKStroke(color: UIColor.blueColor())
            xAxis.majorTickIntervalUnit = TKChartDateTimeAxisIntervalUnit.Hours
            xAxis.majorTickInterval = 4
            xAxis.style.majorTickStyle.ticksHidden = false
            xAxis.range = TKRange(minimum: xMin, andMaximum: xMax)

     

    The end result looks like this:

     

    What I'm missing (if possible) is to "show" the date has changed, so before 00:00 to show yesterday's date (e.g. 12/05) and after 00:00 to show today's date (13/05) so it is more 'user friendly' is this something possible?

     

    Thanks!

     

  2. Konstantinos
    Konstantinos avatar
    4 posts
    Member since:
    May 2015

    Posted 13 May 2015 Link to this post

    The attachment... hopefully it works this time.
  3. DevCraft banner
  4. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 18 May 2015 Link to this post

    Hey, Konstantinos

    You can show dates with hours on your xAxis by adopting TKChartDelegate protocol and implementing its chart:textForAxis:value:atIndex: method:
    - (NSString *)chart:(TKChart *)chart textForAxis:(TKChartAxis *)axis value:(id)value atIndex:(NSUInteger)index
    {
        if (axis.position == TKChartAxisPositionBottom) {
            NSDateFormatter *formatter = [NSDateFormatter new];
            formatter.dateFormat = @"d hh:mm";
            return [formatter stringFromDate:value];
        }
        return [NSString stringWithFormat:@"%@", value];
    }

    Do not forget to set the delegate property of TKChart:
    chart.delegate = self;

    I hope this helps.

    Regards,
    Sophi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top