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

TKChartDateTimeAxisIntervalUnitWeeks broken?

4 Answers 53 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.
Thomas
Top achievements
Rank 1
Thomas asked on 17 Mar 2015, 09:42 AM

Hi,
I tried to get a weekly xAxis working for the TKChartDateTimeAxis,
hence I modified the DateTimeAxis example kindly provided by Telerik.

But there don't seem to be any labels for the interval 'weeks'. Labels for intervals 'month' or
'day' work fine.

Do I need to modify the supplied data to match specific dates?
Is this a bug? Is there any better documentation than this http://docs.telerik.com/devtools/ios/Chart/Axes/datetime ?

I realize that I could use the CategoryAxis and do everything myself, but then
I would need to fill up my data with a lot of zeros since it is sparse.

System:
- Target iOS 7
- iOS SDK 8.2
- Xcode 6.2
- Telerik UI for iOS Q1 2015

Modified example code (one liner in DateTimeAxis.m):

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _chart = [[TKChart alloc] initWithFrame:[self exampleBounds]];
    _chart.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:_chart];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *dateTimeComponents = [[NSDateComponents alloc] init];
    dateTimeComponents.year = 2013;
    dateTimeComponents.day = 1;
    
    NSMutableArray *array = [[NSMutableArray alloc] init];
    for (int i = 1; i <= 6; i++) {
        dateTimeComponents.month = i;
        [array addObject:[[TKChartDataPoint alloc] initWithX:[calendar dateFromComponents:dateTimeComponents] Y:@(arc4random() % 100)]];
    }
    TKChartSplineAreaSeries *series = [[TKChartSplineAreaSeries alloc] initWithItems:array];
    series.selectionMode = TKChartSeriesSelectionModeSeries;
    
    dateTimeComponents.month = 1;
    NSDate *minDate = [calendar dateFromComponents:dateTimeComponents];
    dateTimeComponents.month = 6;
    NSDate *maxDate = [calendar dateFromComponents:dateTimeComponents];
    
    TKChartDateTimeAxis *xAxis = [[TKChartDateTimeAxis alloc] initWithMinimumDate:minDate andMaximumDate:maxDate];
    xAxis.majorTickIntervalUnit = TKChartDateTimeAxisIntervalUnitWeeks; //TKChartDateTimeAxisIntervalUnitMonths;
    xAxis.majorTickInterval = 1;
    _chart.xAxis = xAxis;
    
    [_chart addSeries:series];
}

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 17 Mar 2015, 01:38 PM
Hi Thomas,

It looks like there is an issue with the date time axis when using week interval units. I logged the issue in our issue tracking portal where you can track/comment and vote for the issue. Here is a link to the issue. I updated also your Telerik points for bringing our attention to the issue. We will try to address it in one of our upcoming releases.

As you suggested, one option to work around the issue is to use TKChartCategoryAxis.

Should you have other questions, do not hesitate to ask.

Regards,
Jack
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Thomas
Top achievements
Rank 1
answered on 17 Mar 2015, 01:56 PM
FYI, just stumbled upon a duplicate in your issue tracker:
http://feedback.telerik.com/Project/156/Feedback/Details/152752-fix-tkchartdatetimeaxis-when-majortickintervalunit-is-weeks-the-axis-labels-are
http://feedback.telerik.com/Project/156/Feedback/Details/153592-fix-tkchart-does-not-show-axis-labels-correctly-when-using-date-time-axis-with-w
0
Thomas
Top achievements
Rank 1
answered on 17 Mar 2015, 05:01 PM
We found a much nicer and easier workaround:

xAxis.majorTickIntervalUnit = TKChartDateTimeAxisIntervalUnitDays;
xAxis.majorTickInterval = 7;

NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = @"dd.MM"; // play around with this
xAxis.labelFormatter = formatter;

0
Jack
Telerik team
answered on 18 Mar 2015, 01:33 PM
Hi Thomas,

Thank you for sharing your solution with the community and thank you for pointing out the duplicate issue in our feedback portal. We updated the information on our feedback portal.

We will be glad to help If you need further assistance.

Regards,
Jack
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart
Asked by
Thomas
Top achievements
Rank 1
Answers by
Jack
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or