核心图给出了 SIGABRT 并且不运行 Linegraph
我的代码有问题,核心图给出了 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;
主要:
@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);
}
I have a problem with my code, core plot gives a SIGBRT.
can someone help me ?
Thanks..
header:
@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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
-awakeFromNib
中,您将xvalues
和yvalues
设置为从workingArray
检索的对象。您泄漏了原始值数组,您将xvalues
和yvalues
设置为同一个对象,并且 - 只是猜测而没有看到实际的错误消息 -新对象不是数组。In
-awakeFromNib
, you're settingxvalues
andyvalues
to the object retrieved fromworkingArray
. You're leaking the original value arrays, you're setting bothxvalues
andyvalues
to the same object, and--just guessing without seeing the actual error message--the new object is not an array.