核心图给出了 SIGABRT 并且不运行 Linegraph

发布于 2024-10-24 23:28:13 字数 4456 浏览 4 评论 0原文

我的代码有问题,核心图给出了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

德意的啸 2024-10-31 23:28:13

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

In -awakeFromNib, you're setting xvalues and yvalues to the object retrieved from workingArray. You're leaking the original value arrays, you're setting both xvalues and yvalues to the same object, and--just guessing without seeing the actual error message--the new object is not an array.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文