开发者

Core plot gives a SIGABRT and doesn't run Linegraph

开发者 https://www.devze.com 2023-02-18 06:12 出处:网络
I have a problem with my code, core plot gives a SIGBRT. can someone help me ? Thanks.. header: @interface CorePLotTestAppDelegate : NSObject <CPPlotDataSource>

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*)plo开发者_高级运维t; 
-(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);
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消