我的代码有问题,core plot给出了一个SIGBRT。有人能帮帮我吗?
谢谢..
标题:
@interface CorePLotTestAppDelegate : NSObject <CPPlotDataSource>
{
IBOutlet CPLayerHostingView *view;
CPXYGraph *graph;
NSMutableArray *xvalues;
NSMutableArray *yvalues;
}
-(void)clear;
-(void)addPointFloat:(float)x y:(float)y;
-(void)addPointNumber:(NSNumber*)x y:(NSNumber*)y;
// CPPlotDataSource protocol:
-(NSUInteger)numberOfRecordsForPlot:(CPPlot*)plot;
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index;main:
@implementation CorePLotTestAppDelegate
-(id)init
{
if ([super init]) {
xvalues = [[NSMutableArray alloc] init];
yvalues = [[NSMutableArray alloc] init];
}
return self;
}
-(void)dealloc
{
[xvalues release];
[yvalues release];
[graph release];
[super dealloc];
}
-(void)clear
{
[xvalues removeAllObjects];
[yvalues removeAllObjects];
}
-(void)addPointFloat:(float)x y:(float)y
{
[xvalues addObject:[NSNumber numberWithFloat:x]];
[yvalues addObject:[NSNumber numberWithFloat:y]];
}
-(void)addPointNumber:(NSNumber*)x y:(NSNumber*)y
{
[xvalues addObject:x];
[yvalues addObject:y];
}
-(NSUInteger)numberOfRecordsForPlot:(CPPlot*)plot
{
return [xvalues count];
}
-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum
recordIndex:(NSUInteger)index
{
if (fieldEnum == CPScatterPlotFieldX)
return [xvalues objectAtIndex:index];
else
return [yvalues objectAtIndex:index];
}
- (void) awakeFromNib
{
//Daten YAchse
NSString *filePath = @"pegel";//file path...
NSString *fileRoot = [[NSBundle mainBundle] pathForResource:filePath ofType:@"txt"];
// read everything from text
NSString *fileContents = [NSString stringWithContentsOfFile:fileRoot encoding:NSUTF8StringEncoding error:nil];
// first, separate by new line
NSArray *allLinedStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
// then break down even further
NSString *strsInOneLine;
int d;
for (d=0; d < [allLinedStrings count]; d=d+1) {
strsInOneLine = [allLinedStrings objectAtIndex:d];
// choose whatever input identity you have decided. in this case ;
NSArray *workingArray = [strsInOneLine componentsSeparatedByString:@";"];
NSMutableArray *pegel = [workingArray lastObject];
yvalues = pegel;
xvalues = pegel;
NSLog(@"%@", pegel);
}
// Create graph and set a theme
graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
CPTheme *theme = [CPTheme themeNamed:kCPDarkGradientTheme];
[graph applyTheme:theme];
view.hostedLayer = graph;
// Setup plot space
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-3) length:CPDecimalFromFloat(20.0)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-3.5) length:CPDecimalFromFloat(10.0)];
// ScatterPlot
CPScatterPlot *linePlot = [[[CPScatterPlot alloc] init] autorelease];
linePlot.identifier = @"LinienDiagramm";
linePlot.dataLineStyle.lineWidth = 3.f;
linePlot.dataLineStyle.lineColor = [CPColor blueColor];
linePlot.dataSource = self;
[graph addPlot: linePlot];
// linien effekt
CPGradient *areaGradient =
[CPGradient gradientWithBeginningColor:[CPColor blueColor]
endingColor:[CPColor blackColor]];
areaGradient.angle = -90.0f;
linePlot.areaFill = [CPFill fillWithGradient:areaGradient];
linePlot.areaBaseValue = CPDecimalFromString(@"0");
// X und Y achse einstellungen
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x = axisSet.xAxis;
CPXYAxis *y = axisSet.yAxis;
// x-achse
x.minorTicksPerInterval = 5;
x.minorTickLength = 2.0f;
x.majorTickLength = 7.0f;
x.labelOffset = 2.0f;
x.labelRotation = 45;
x.majorIntervalLength = CPDecimalFromFloat(5.0f);
// y-achse
y.minorTicksPerInterval = 5;
y.minorTickLength = 2.0f;
y.majorTickLength = 7.0f;
y.labelOffset = 5.0f;
y.majorIntervalLength = CPDecimalFromFloat(5.0f);
NSLog(@"%@", graph);
}发布于 2011-03-26 07:31:18
在-awakeFromNib中,您将xvalues和yvalues设置为从workingArray检索的对象。您泄漏了原始的值数组,将xvalues和yvalues都设置为同一个对象,并且--只是在没有看到实际错误消息的情况下猜测--新对象不是数组。
https://stackoverflow.com/questions/5395715
复制相似问题