This is a migrated thread and some comments may be shown as answers.

DateTime xAxis question

2 Answers 99 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Konstantinos
Top achievements
Rank 1
Konstantinos asked on 13 May 2015, 01:54 PM

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 Answers, 1 is accepted

Sort by
0
Konstantinos
Top achievements
Rank 1
answered on 13 May 2015, 01:56 PM
The attachment... hopefully it works this time.
0
Sophi
Telerik team
answered on 18 May 2015, 09:13 AM
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
Tags
Chart
Asked by
Konstantinos
Top achievements
Rank 1
Answers by
Konstantinos
Top achievements
Rank 1
Sophi
Telerik team
Share this question
or