Dealing with Nil value in series

4 posts, 0 answers
  1. Jeffrey
    Jeffrey avatar
    2 posts
    Member since:
    Oct 2010

    Posted 16 Jan 2015 Link to this post

    I'd like to show a gap in a line and area series. I'm able to assign nil to the y value of a TKChartDataPoint but when generating the chart, I receive a run time error. To get around, I'm simply using 0, however, that significantly changes the chart. I'd rather simply have a gap where the value is nil.

    Is this possible with the Telerik iOS controls?
  2. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 20 Jan 2015 Link to this post

    Hello Jeffrey,

    Thank you for contacting us.

    Currently TKChart does not support empty values. This is a must have feature and we will implement it one of our upcoming releases. It is logged also in our feedback portal as a feature request. Feel free to vote/comment.
    One option to work around the issue is creating 2 line series instead of assigning 0 to the data point y value. Consider the code snippet below:
    NSMutableArray *items = [[NSMutableArray alloc] init];
    [chart beginUpdates];
    for (int i = 0; i < dataPoints.count; i++) {
        TKChartDataPoint *point = (TKChartDataPoint *)dataPoints[i];
        if (point.dataYValue == nil) {
            TKChartLineSeries *series = [[TKChartLineSeries alloc] initWithItems:items];
            [chart addSeries:series];
            items = [[NSMutableArray alloc] init];
        }
        else {
            [items addObject:point];
        }
              
        if (i == dataPoints.count - 1 && items.count > 0) {
            TKChartLineSeries *series = [[TKChartLineSeries alloc] initWithItems:items];
             [chart addSeries:series];
        }
    }
    [chart endUpdates];

    i hope this helps. If you have further questions I will be glad to assist you.

    Regards,
    Adrian
    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. Aravinth
    Aravinth avatar
    1 posts
    Member since:
    Mar 2015

    Posted 30 Mar 2015 in reply to Adrian Link to this post

    If I had all the values for a given data set,
    it'd look like this:
    1----2----3----4----5

     *in case missing the 3rd value
    yourSolution:
    1----2            4----5
            \           /
             \         /
             
    Ideally, what i'm looking for
    1----2---------4----5
  5. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 30 Mar 2015 Link to this post

    Hello Aravinth,

    Thank you for contacting us.

    To achieve the described scenario you should filter your data points array removing the data points that have nil value for their y value. This can be done easily by using a predicate. Please consider the code snippet below:
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dataYValue != nil"];
    NSArray *items = [dataPoints filteredArrayUsingPredicate:predicate];
         
    TKChartLineSeries *series = [[TKChartLineSeries alloc] initWithItems:items];

    I hope this helps. Do not hesitate to contact us in case you need further assistance.

    Regards,
    Adrian
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
DevCraft banner