首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心图给出一个SIGABRT,但不运行Linegraph

核心图给出一个SIGABRT,但不运行Linegraph
EN

Stack Overflow用户
提问于 2011-03-23 01:57:04
回答 1查看 308关注 0票数 0

我的代码有问题,core plot给出了一个SIGBRT。有人能帮帮我吗?

谢谢..

标题:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
@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);
}
EN

回答 1

Stack Overflow用户

发布于 2011-03-26 07:31:18

-awakeFromNib中,您将xvaluesyvalues设置为从workingArray检索的对象。您泄漏了原始的值数组,将xvaluesyvalues都设置为同一个对象,并且--只是在没有看到实际错误消息的情况下猜测--新对象不是数组。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5395715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档