我已经设置了一个带有核心图的图表,该图表在存在要显示的新数据时显示动画。我按照CorePlot的示例代码进行操作,并且这是:
这是计时器每秒激活的代码块:
-(void)newData {
CPTGraph *graphTop = self.hostViewTop.hostedGraph;
CPTPlot *plotTop = [graphTop plotWithIdentifier:@"TWD"];
if (plotTop) {
if (twdData.count > 3600) {
NSRange range;
range.location = 0;
range.length = twdData.count-3600;
[twdData removeObjectsInRange:range];
[plotTop deleteDataInIndexRange:range];
}
thePlotSpaceTop = (CPTXYPlotSpace *)graphTop.defaultPlotSpace;
NSUInteger location = (currentIndexTWD > twdDataRange ? currentIndexTWD - twdDataRange + 1 : 0);
CPTPlotRange *newXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(location)
length:CPTDecimalFromUnsignedInteger(twdDataRange)];
[CPTAnimation animate:thePlotSpaceTop
property:@"xRange"
fromPlotRange:thePlotSpaceTop.xRange
toPlotRange:newXRange
duration:CPTFloat(0.1)];
currentIndexTWD++;
...
double avgTWD = 0.0;
int maxTWD = ...
int minTWD = ...
CPTPlotRange *newYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(minTWD) length:CPTDecimalFromInt((maxTWD-minTWD)+(maxTWD-minTWD)/3.5)];
[CPTAnimation animate:thePlotSpaceTop
property:@"yRange"
fromPlotRange:thePlotSpaceTop.yRange
toPlotRange:newYRange
duration:CPTFloat(0.2)];
[CPTAnimation animate:((CPTXYAxisSet *) graphTop.axisSet).xAxis
property:@"orthogonalCoordinateDecimal"
fromDecimal:((CPTXYAxisSet *) graphTop.axisSet).xAxis.orthogonalCoordinateDecimal
toDecimal:CPTDecimalFromInt(minTWD) duration:CPTFloat(0.2)];
}
((CPTScatterPlot *)plotTop).areaBaseValue = CPTDecimalFromInt(minTWD);
NSNumber *newData;
if ([plotTop cachedDataCount] > 50) {
newData = [NSDecimalNumber numberWithDouble:[Utils randomBetweenMin:0 andMax:20]];
} else if ([plotTop cachedDataCount] > 20) {
newData = [NSDecimalNumber numberWithDouble:[Utils randomBetweenMin:2 andMax:12]];
} else {
newData = [NSDecimalNumber numberWithDouble:[Utils randomBetweenMin:minTWDVal andMax:maxTWDVal]];
}
int newTwdData = [newData intValue];
...
[twdData addObject:[NSNumber numberWithInt:(int)calculatedTwd]];
lastTwd = calculatedTwd;
[plotTop insertDataAtIndex:twdData.count - 1 numberOfRecords:1];
graphTop.title = [NSString stringWithFormat:@"TWD %d° avg %d°", newTwdData, (int)avgTWD];
}
}
这是我的错误日志:
Path: /private/var/mobile/Containers/Bundle/Application/2E266FC1-3963-4AFB-890E-F6EFBDEC8AB9/ESA Instruments.app/ESA Instruments
Identifier: com.astrayacht.ESA-Instruments
Version: 1.0 (1.0)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2015-01-09 15:35:50.512 +0100
Launch Time: 2015-01-09 15:35:44.833 +0100
OS Version: iOS 8.1.2 (12B440)
Report Version: 105
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x439c9ac4308870de
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x000000019432bbdc objc_msgSend + 28
1 ESA Instruments 0x000000010015a268 -[CPTXYPlotSpace setXRange:] + 192
2 ESA Instruments 0x000000010018ca0c -[CPTAnimation update:] + 2088
3 Foundation 0x0000000184a96e14 __NSFireTimer + 88
4 CoreFoundation 0x0000000183b7a8d4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 24
5 CoreFoundation 0x0000000183b7a584 __CFRunLoopDoTimer + 884
6 CoreFoundation 0x0000000183b77fd0 __CFRunLoopRun + 1368
7 CoreFoundation 0x0000000183aa50a0 CFRunLoopRunSpecific + 392
8 GraphicsServices 0x000000018cc475a0 GSEventRunModal + 164
9 UIKit 0x00000001883da3bc UIApplicationMain + 1484
10 ESA Instruments 0x0000000100117a60 main (main.m:16)
11 libdyld.dylib 0x0000000194986a04 start + 0
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x0000000194a84c94 kevent64 + 8
1 libdispatch.dylib 0x000000019496c97c _dispatch_mgr_invoke + 272
2 libdispatch.dylib 0x000000019495f3b0 _dispatch_mgr_thread + 48
Thread 2:
0 libsystem_kernel.dylib 0x0000000194a9fc78 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x0000000194b39390 _pthread_wqthread + 988
2 libsystem_pthread.dylib 0x0000000194b38fa4 start_wqthread + 0
Thread 3:
0 libsystem_kernel.dylib 0x0000000194a9fc78 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x0000000194b39390 _pthread_wqthread + 988
2 libsystem_pthread.dylib 0x0000000194b38fa4 start_wqthread + 0
Thread 4:
0 libsystem_kernel.dylib 0x0000000194a9fc78 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x0000000194b39390 _pthread_wqthread + 988
2 libsystem_pthread.dylib 0x0000000194b38fa4 start_wqthread + 0
Thread 5:
0 libsystem_kernel.dylib 0x0000000194a9fc78 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x0000000194b39390 _pthread_wqthread + 988
2 libsystem_pthread.dylib 0x0000000194b38fa4 start_wqthread + 0
Thread 6:
0 libsystem_kernel.dylib 0x0000000194a84e7c mach_msg_trap + 8
1 libsystem_kernel.dylib 0x0000000194a84cf4 mach_msg + 68
2 CoreFoundation 0x0000000183b79ecc __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x0000000183b77e20 __CFRunLoopRun + 936
4 CoreFoundation 0x0000000183aa50a0 CFRunLoopRunSpecific + 392
5 CoreFoundation 0x0000000183af71f8 CFRunLoopRun + 108
6 CoreMotion 0x00000001844a298c 0x184460000 + 272780
7 libsystem_pthread.dylib 0x0000000194b3be7c _pthread_body + 160
8 libsystem_pthread.dylib 0x0000000194b3bdd8 _pthread_start + 156
9 libsystem_pthread.dylib 0x0000000194b38fac thread_start + 0
Thread 7:
0 libsystem_kernel.dylib 0x0000000194a9fc78 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x0000000194b39390 _pthread_wqthread + 988
2 libsystem_pthread.dylib 0x0000000194b38fa4 start_wqthread + 0
Thread 0 crashed with ARM Thread State (64-bit):
x0: 0x00000001985bc3c8 x1: 0x000000010019d10e x2: 0x0000000174278d40 x3: 0x000000016fd714c8
x4: 0x000000016fd71508 x5: 0x0000000000000001 x6: 0x3736363636312e30 x7: 0x0000000000000000
x8: 0x000000010015a1a8 x9: 0x0000000100ad96c0 x10: 0x439c9ac42f00709e x11: 0x459c88c4459c8ac4
x12: 0x439c9ac4308870de x13: 0x00ad960100ad96c0 x14: 0x0000000000000000 x15: 0x00000001742e5889
x16: 0x000000019432bbc0 x17: 0x0000000000000000 x18: 0x0000000000000000 x19: 0x0000000174142890
x20: 0x00000001985bc3c8 x21: 0x000000018e0f66b2 x22: 0x000000010019d10e x23: 0x0000000000000005
x24: 0x0000000174273200 x25: 0x0000000000000028 x26: 0x00000001001a11c6 x27: 0x0000000174056b30
x28: 0x0000000188b4630c fp: 0x000000016fd715b0 lr: 0x000000010015a26c
sp: 0x000000016fd71560 pc: 0x000000019432bbdc cpsr: 0x20000000
提前感谢您的帮助