我在视图控制器中显示了 2 个图表。y 轴是记录的时间值,x 是数据,风量、阵风、平均值。我的问题是我的阵列中的数据收集时间超过了大约 8-10 小时。所以有时第一个值是晚上 19:00,最后一个值是早上 05:00。现在,如果我尝试将其放入散点图中,数据将遍布各处,而不是按顺序排列。如果我只使用数组索引号,它会绘制得很漂亮,但数据并不总是按时间顺序排列,有时一个小时可以在没有数据的地方过去。当我将 y 轴更改为记录的时间值时,我从 HH:mm:ss 和之前的示例转换为 19.0 和 5.0,如下所示,绘图是错误的。我已经在 y 轴上添加了自定义标签等,但需要一种方法使其成为线性?
编辑:
我希望 x 轴如下所示,当数据具有前一天和当天时,轴编号运行如下??:
19,20,21,22,23,24,1,2,3,4,5,6
目前我有一个客户标签循环来做到这一点,但数据仍然环绕?
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat([xFirstEntry integerValue]) length:CPTDecimalFromFloat(10.5)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat([yMaxValue integerValue]+12)];
plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble([xFirstEntry integerValue]) length:CPTDecimalFromDouble(10.5)];
plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromDouble([yMaxValue doubleValue]*1.23)];
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"1"] decimalValue];
x.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];
x.labelingPolicy = CPTAxisLabelingPolicyNone;
xFirstEntry = [[[changedArray objectAtIndex:0]objectForKey:@"date"] substringFromIndex:11];
xFirstEntry = [xFirstEntry substringToIndex:[xFirstEntry length] - 6];
xLastEntry = [[[changedArray objectAtIndex:changedArray.count-1]objectForKey:@"date"] substringFromIndex:11];
xLastEntry = [xLastEntry substringToIndex:[xLastEntry length] - 6];
NSLog(@"%@ %@", xFirstEntry, xLastEntry);
NSMutableArray *xCustomTickLocations = [[NSMutableArray alloc]init];
NSMutableArray *xCustomAxisLabels = [[NSMutableArray alloc]init];
NSInteger newValue = [xFirstEntry integerValue];
if ([xFirstEntry integerValue] > [xLastEntry integerValue]) {
NSLog(@"gretaer than");
while (newValue <= 24) {
[xCustomTickLocations addObject:[NSDecimalNumber numberWithInt:newValue]];
[xCustomAxisLabels addObject:[NSString stringWithFormat:@"%d",newValue]];
newValue++;
}
newValue = 1;
[xCustomTickLocations addObject:[NSDecimalNumber numberWithInt:newValue]];
[xCustomAxisLabels addObject:[NSString stringWithFormat:@"%d",newValue]];
while (newValue <= [xLastEntry integerValue]+1) {
[xCustomTickLocations addObject:[NSDecimalNumber numberWithInt:newValue]];
[xCustomAxisLabels addObject:[NSString stringWithFormat:@"%d",newValue]];
newValue++;
}
}
else {
NSLog(@"less than");
while (newValue <= [xLastEntry integerValue]+1) {
[xCustomTickLocations addObject:[NSDecimalNumber numberWithInt:newValue]];
[xCustomAxisLabels addObject:[NSString stringWithFormat:@"%d",newValue]];
newValue++;
}
}
NSUInteger XlabelLocation = 0;
CPTMutableTextStyle *xLabelStyle = [CPTMutableTextStyle textStyle];
xLabelStyle.color = [[CPTColor whiteColor] colorWithAlphaComponent:1];
xLabelStyle.fontName = @"Helvetica-Bold";
xLabelStyle.fontSize = 9.0f;
NSMutableArray *XcustomLabels = [NSMutableArray arrayWithCapacity:[xCustomAxisLabels count]];
for (NSNumber *XtickLocation in xCustomTickLocations) {
CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [xCustomAxisLabels objectAtIndex:XlabelLocation++] textStyle:xLabelStyle];
newLabel.tickLocation = [XtickLocation decimalValue];
newLabel.offset = 2;
newLabel.rotation=M_PI_2;
[XcustomLabels addObject:newLabel];
}
x.axisLabels = [NSSet setWithArray:XcustomLabels];