Good morning Yoanna, thank you much for getting back to me so fast, I am listing my methods that produce a working Telerik chart based on my data. My data comes from tapping a tableView cell and populates the Chart with no issues, however when I try to implement the Series for Date Line I get errors, Below is the code that works, maybe you can show me how to incorporate what you sent as Demo code into my project. I cannot get it to work.
The (void) method below is called when a user taps a tableView Cell , and like i mentioned it produces a chart, however when I try to implement the Series like you showed me it does not work.
-(void) showChartData {
if (sleepDataVC.date > 0) {
TKChart *chartTop = [[TKChart alloc]initWithFrame:CGRectMake(_scrollView.bounds.origin.x,_scrollView.bounds.origin.y, _scrollView.bounds.size.width, _scrollView.bounds.size.height)];
chartTop.dataSource = self;
chartTop.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollView addSubview:chartTop];
/*
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *dateTimeComponents = [[NSDateComponents alloc] init];
dateTimeComponents.year = 2015;
dateTimeComponents.month = 5;
dateTimeComponents.day = 7;
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int i = 1; i <= 6; i++) {
dateTimeComponents.hour = i;
[array addObject:[[TKChartDataPoint alloc] initWithX:[calendar dateFromComponents:dateTimeComponents] Y:@(arc4random() % 100)]];
}
TKChartSplineAreaSeries *series = [[TKChartSplineAreaSeries alloc] initWithItems:array];
series.selectionMode = TKChartSeriesSelectionModeSeries;
dateTimeComponents.hour= 1;
NSDate *minDate = [calendar dateFromComponents:dateTimeComponents];
dateTimeComponents.hour = 6;
NSDate *maxDate = [calendar dateFromComponents:dateTimeComponents];
TKChartDateTimeAxis *xAxis = [[TKChartDateTimeAxis alloc] initWithMinimumDate:minDate andMaximumDate:maxDate];
xAxis.majorTickIntervalUnit = TKChartDateTimeAxisIntervalUnitHours;
xAxis.majorTickInterval = 1;
chartTop.xAxis = xAxis;
[chartTop addSeries:series];
*/
} else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Baby G" message:@"There is No Sleep Data" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"Record Sleep Data and try again", nil];
[alert show];
}
}
- (NSUInteger)numberOfSeriesForChart:(TKChart *)chart
{
return 1;
}
- (TKChartSeries *)seriesForChart:(TKChart *)chart atIndex:(NSUInteger)index
{
TKChartLineSeries *series = [chart dequeueReusableSeriesWithIdentifier:@"series1"];
if (!series) { //_tkCountArray
series = [[TKChartLineSeries alloc] initWithItems:_tkCountArray reuseIdentifier:@"series1"];
series.title = @"Delegate series";
}
return series;
}
- (NSUInteger)chart:(TKChart *)chart numberOfDataPointsForSeriesAtIndex:(NSUInteger)seriesIndex
{
return tkChartCount;
}
- (id<TKChartData>)chart:(TKChart *)chart dataPointAtIndex:(NSUInteger)dataIndex forSeriesAtIndex:(NSUInteger)seriesIndex
{
//dataIndex
TKChartDataPoint *point = [[TKChartDataPoint alloc] initWithX:@(dataIndex)Y:@(arc4random() % 100)];
return point;
}
Thank you so much.
JZ