【发布时间】:2011-04-13 02:51:31
【问题描述】:
我已经尝试过核心图中的所有示例,尤其是 dateplot 示例,但我仍然坚持沿 x 轴以小时数来实现该图。请帮我找出我哪里出错了。
我面临的问题:
- 无法获得小时均匀分布的轴(按小时计算,0900、1000、....)
- 当我将它存储到 plotData 数组中并且绘制图形时,所有 x 值都是 0。我的意思是,所有值都仅绘制在 y 轴上。不存储 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;
}
【问题讨论】:
标签: iphone objective-c graph nsdate core-plot