Я пробовал пройти все примеры в основном графике, особенно в примере графика даты, но все же я застрял в реализации графика с часами вдоль оси x. Пожалуйста, помогите мне выяснить, в чем я ошибаюсь.
Проблемы, с которыми я сталкиваюсь:
Код следующий:
NSDateFormatter *dateFormatter1 = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter1 setDateFormat:@"HH:mm a"];
NSTimeInterval oneDay = 24 * 60 * 60;
NSTimeInterval xLow = 0.0f;
//This part is used to set up the plot space.
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.allowsUserInteraction=YES;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLow)
length:CPDecimalFromFloat(oneDay)];
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x=axisSet.xAxis;
x.majorIntervalLength = CPDecimalFromFloat(1*60*60);
x.minorTicksPerInterval = 0;
x.axisLineStyle = lineStyle;
x.majorTickLength = 7.0f;
//x.visibleRange=xAxisRange;
CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc]
initWithDateFormatter:dateFormatter1] autorelease];
Chirp *retValue=[someTemp objectAtIndex:0];
NSDate *tempDate=retValue.startingAt;
timeFormatter.referenceDate = tempDate;
x.labelFormatter = timeFormatter;
x.orthogonalCoordinateDecimal=CPDecimalFromString(@"0");
NSMutableArray *newData = [NSMutableArray array];
NSUInteger i;
for ( i = 0; i < [someTemp count]; i++ )
{
Chirp *retValue=[[Chirp alloc]init];
retValue=[someTemp objectAtIndex:i];
NSDate *tempDate=retValue.startingAt;
NSString *dateFromString=[dateFormatter1 stringFromDate:tempDate];
NSLog(@"%@", dateFromString);
id x=dateFromString;
id y=[NSDecimalNumber numberWithFloat:[retValue.chipCount floatValue]];
[newData addObject:
[NSDictionary dictionaryWithObjectsAndKeys:
x, [NSNumber numberWithInt:CPScatterPlotFieldX],
y, [NSNumber numberWithInt:CPScatterPlotFieldY],
nil]];
}
plotData = newData;
-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot
{
return plotData.count;
}
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
NSDecimalNumber *num = [[plotData objectAtIndex:index] objectForKey:[NSNumber numberWithInt:fieldEnum]];
return num;
}