3

ポイントを追加しようとすると、エラーが発生します。この問題を修正する方法がわかりません。

完了しないのは次のブロックです。

-(void)addNewData:(NSArray*)data{}

誰かがこの問題を解決するのを手伝ってくれませんか、ありがとう。

私のエラー:

I get the following error:
2012-09-24 14:51:09.790 sense_01[6719:907] ACC Connect
2012-09-24 14:51:15.270 sense_01[6719:907] *** Assertion failure in -[CPTScatterPlot reloadDataInIndexRange:], /Users/eskroch/Projects/Core Plot/framework/Source/CPTPlot.m:442
2012-09-24 14:51:15.272 sense_01[6719:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: NSMaxRange(indexRange) <= [self.dataSource numberOfRecordsForPlot:self]'
*** First throw call stack:
(0x394702a3 0x31d8f97f 0x3947015d 0x383da2af 0xaba75 0xaeccb 0xabcbb 0xaefeb 0xa7235 0xa360f 0x363df0ad 0x363df05f 0x363df03d 0x363de8f3 0x363dede9 0x363075f9 0x362f4809 0x362f4123 0x352f15a3 0x352f11d3 0x39445173 0x39445117 0x39443f99 0x393b6ebd 0x393b6d49 0x352f02eb 0x36348301 0xa2795 0xa2730)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

私のコード:

//
//  SingleSensorViewController.m
//  sense_01
//
//  Created by Morten Ydefeldt on 9/21/12.
//  Copyright (c) 2012 ydefeldt. All rights reserved.
//

#import "SingleSensorViewController.h"



@interface SingleSensorViewController ()

@end


@implementation SingleSensorViewController

@synthesize plot,graphView,label,SingleGraphView,portNumberForGraph,plotValues,plotLine;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        SingleGraphView = self.view;
        CATransition *transition = [CATransition animation];
        transition.duration = .5;
        transition.type = kCATransitionMoveIn; //choose your animation
        transition.subtype = kCATransitionFromTop;
        [SingleGraphView.layer addAnimation:transition forKey:nil];
        plotLine = [plot plotWithIdentifier:@"1"];

    }
    return self;
}

-(void)addNewData:(NSArray*)data{

    plotValues = [NSMutableArray arrayWithArray:data];
    int i = [plotValues count];
    [plotLine insertDataAtIndex:[plotValues count]-1 numberOfRecords:1];
    NSLog(@"DONE");
}

-(void)pointReceived:(NSNumber *) point{

    NSLog(@"some number");

}

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot{

    return [plotValues count];
}


-(NSNumber *)numberForPlot:(CPTPlot*)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index{

    if (fieldEnum == CPTScatterPlotFieldX){
        return [NSNumber numberWithInt:[plotValues count]];

    }else{
        //return [plotValues objectAtIndex:plotValues.count-1];
        return [NSNumber numberWithInt:[plotValues count]];

    }

}


-(id)getView{
    return SingleGraphView;
}

//-(CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)proposedDisplacementVector
//{
//    NSLog(@"PLOT SPACE");
//
//return CGPointMake(proposedDisplacementVector.x, proposedDisplacementVector.y);
//
//}
//
//-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate
//{
//    
//    
//    
//    //    if (coordinate == CPTCoordinateY) {
//    //        newRange = ((CPTXYPlotSpace*)space).yRange;
//    //    }
//    NSLog(@"NEW RANGE");
//    return newRange;
//    
//    
//}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    plot = [[CPTXYGraph alloc] initWithFrame:CGRectMake(100, 10, 800, 180)];
    //CPTGraphHostingView *layerHostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(100, 10, 800, 180)];
    graphView.collapsesLayers = NO;
    graphView.hostedGraph = plot;

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace* )plot.defaultPlotSpace;
    plotSpace.allowsUserInteraction = YES;
    plotSpace.delegate = self;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation: CPTDecimalFromDouble(0.0) length: CPTDecimalFromDouble(20.0)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation: CPTDecimalFromDouble(0.0) length: CPTDecimalFromDouble(50.0)];

    CPTScatterPlot *line = [[CPTScatterPlot alloc]init];
    CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];

    //Fill colors
    float c= 0.2;
    plot.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:c green:c blue:c alpha:0]];
    plot.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:c green:c blue:c alpha:0.3]];
    plot.plotAreaFrame.borderLineStyle = nil;

    //Plot border
    lineStyle.lineColor = [CPTColor grayColor];
    lineStyle.lineWidth = 1.2;
    //plot.borderLineStyle = lineStyle;

    //Plot padding
    plot.paddingBottom = 5;
    plot.paddingLeft = 5;
    plot.paddingRight = 5;
    plot.paddingTop = 5;

    //axis range
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)plot.axisSet;
    CPTXYAxis *y = axisSet.yAxis;
    CPTXYAxis *x = axisSet.xAxis;
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0.0");
    y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0.0");

    y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
    x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;

    x.axisConstraints = [CPTConstraints constraintWithLowerOffset:15.0];
    y.axisConstraints = [CPTConstraints constraintWithLowerOffset:35.0];

    y.minorTickLength = 0;
    y.majorTickLength = 0;
    x.minorTickLength = 0;
    x.majorTickLength = 0;

    //axis theming
    c = 0.4;
    lineStyle.lineColor = [CPTColor colorWithComponentRed:c green:c blue:c alpha:1];
    lineStyle.lineWidth = 0.7f;
    y.axisLineStyle = lineStyle;
    x.axisLineStyle = lineStyle;


    //label theming
    CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
    textStyle.color = [CPTColor whiteColor];
    textStyle.fontName = @"Helvetica-Bold";
    x.labelTextStyle = textStyle;
    y.labelTextStyle = textStyle;

    //grid theming
    c = 0.3;
    lineStyle.lineColor = [CPTColor colorWithComponentRed:c green:c blue:c alpha:1];
    lineStyle.lineWidth = 0.1f;
    x.minorGridLineStyle = lineStyle;
    y.minorGridLineStyle = lineStyle;


    //curve theming
    lineStyle.miterLimit = 1.0f;
    lineStyle.lineWidth = 1.5f;
    lineStyle.lineColor = [CPTColor whiteColor];
    line.dataLineStyle = lineStyle;
    line.identifier = @"1";
    line.dataSource = self;


    //plotsymbol
    CPTPlotSymbol *plotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
    CPTGradient *blueGradient = [CPTGradient gradientWithBeginningColor:[CPTColor colorWithComponentRed:62.0f/255.0f green:112.0/255.0f blue:184.0f/255.0f alpha:1] endingColor:[CPTColor colorWithComponentRed:43.0f/255.0f green:63.0/255.0f blue:153.0f/255.0f alpha:1]];
    lineStyle.lineColor = [CPTColor whiteColor];
    lineStyle.lineWidth = 1.0f;
    plotSymbol.lineStyle = lineStyle;
    plotSymbol.fill = [CPTFill fillWithGradient:blueGradient];
    plotSymbol.size = CGSizeMake(11.0, 11.0);
    line.plotSymbol = plotSymbol;

    line.delegate = self;
    line.plotSymbolMarginForHitDetection = 5.0f;

    [plot addPlot:line];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [self setGraphView:nil];
    [self setLabel:nil];
    [self setIconimage:nil];
    [super viewDidUnload];



}


- (IBAction)addPoint:(id)sender {
    NSLog(@"ADD POINT");
}
@end
4

2 に答える 2

2
  1. データ配列全体を置き換えるため、 の-reloadData代わりに メソッドを使用し- insertDataAtIndex:numberOfRecords:ます。既存のデータ セットにデータ ポイントを追加する必要がある場合は、データを挿入します。

  2. plotValues配列を保持する必要があります。そうしないと、Core Plot が読み取ろうとするまでに配列の割り当てが解除され、ジャンク データまたはクラッシュが発生する可能性があります。

于 2012-09-25T00:57:25.897 に答える
0

この問題の原因は、グラフにポイントを追加しようとするとビューが不要になることであることがわかりました。

[self addNewData:[NSArray arrayWithObject:@"23"]];

viewdidload の最後にポイントが追加され、すべてが機能します!

于 2012-09-25T01:42:45.083 に答える