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

Dealing with Nil value in series

3 Answers 86 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.
Jeffrey
Top achievements
Rank 1
Jeffrey asked on 16 Jan 2015, 05:42 PM
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?

3 Answers, 1 is accepted

Sort by
0
Adrian
Telerik team
answered on 20 Jan 2015, 08:41 AM
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.

 
0
Aravinth
Top achievements
Rank 1
answered on 30 Mar 2015, 11:51 AM
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
0
Adrian
Telerik team
answered on 30 Mar 2015, 01:22 PM
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.

 
Tags
Chart
Asked by
Jeffrey
Top achievements
Rank 1
Answers by
Adrian
Telerik team
Aravinth
Top achievements
Rank 1
Share this question
or