Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:36:15+00:00 2026-06-11T20:36:15+00:00

I am having trouble with the core-plot library, if I try to add a

  • 0

I am having trouble with the core-plot library, if I try to add a point I get the an error. I dont know how to fix this issue.

It is the following block which does not complete:

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

Can someone please help me resolve this problem, thanks.

My error:

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) 

My code:

//
//  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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:36:16+00:00Added an answer on June 11, 2026 at 8:36 pm
    1. Since you’re replacing the entire data array, use the -reloadData method instead of - insertDataAtIndex:numberOfRecords:. You insert data when you need to add data points to an existing data set.

    2. You need to retain the plotValues array. Otherwise, the array might be deallocated by the time Core Plot tries to read it and you’ll get junk data or a crash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having trouble rindexing product_data, i get this error: (p.s i've recently changed hosting
I'm having trouble using the Core Plot framework in my project. I tried following
I am having trouble understanding how to best use Core Data to solve this
I've been looking into core-plot for the iPhone and I'm having trouble finding any
I'm having some trouble getting my Core Data entities to play nice and order
I am having trouble saving a photo into core data. I am trying to
Having trouble with each function... Will try to explain by example... In my code,
Having trouble framing this assertion in Rspec for my rails app. A User has
I am having trouble understanding how Core Data works conceptually and in terms of
I am building a core data iphone app, and having trouble with retrieving one-many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.