TKChartDateTimeAxisIntervalUnitWeeks broken?

5 posts, 0 answers
  1. Thomas
    Thomas avatar
    5 posts
    Member since:
    Mar 2015

    Posted 17 Mar 2015 Link to this post

    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];
    }

  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 17 Mar 2015 Link to this post

    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.

     
  3. DevCraft banner
  4. Thomas
    Thomas avatar
    5 posts
    Member since:
    Mar 2015

    Posted 17 Mar 2015 in reply to Jack Link to this post

    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
  5. Thomas
    Thomas avatar
    5 posts
    Member since:
    Mar 2015

    Posted 17 Mar 2015 Link to this post

    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;

  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 18 Mar 2015 Link to this post

    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.

     
Back to Top
DevCraft banner