ios - Problems with Core Plot Graph on device but not on simulator -
i'm trying use core plot create graph of 3 investment scenarios on ipad.
i'm using xcode 5, ipad 4, , ios 7.
the basic premise user enters initial investment , interest rate 3 different investments , upon clicking button, second view displayed shows core plot scatter plot representation of each scenario on same plot space.
my problem when run application on ipad (the actual device), resulting graph has plots equal y = 0 (this displayed, can't post pictures due need higher reputation stack overflow)
however, in ipad simulator in xcode graph appears properly, equations have set using data input initial data view.
i have 2 uiviews 2 separate view controllers. 1 data, , 1 graph display. code following:
dataviewcontroller.h
#import <uikit/uikit.h> @interface dataviewcontroller : uiviewcontroller @property (weak, nonatomic) iboutlet uitextfield *principalonetext; @property (weak, nonatomic) iboutlet uitextfield *rateonetext; @property (weak, nonatomic) iboutlet uitextfield *principaltwotext; @property (weak, nonatomic) iboutlet uitextfield *ratetwotext; @property (weak, nonatomic) iboutlet uitextfield *principalthreetext; @property (weak, nonatomic) iboutlet uitextfield *ratethreetext; @property (weak, nonatomic) iboutlet uibutton *viewgraphbutton; - (ibaction)hidekeyboard:(id)sender; @end
and dataviewcontroller.m
#import "dataviewcontroller.h" @interface dataviewcontroller () @end @implementation dataviewcontroller - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (ibaction)hidekeyboard:(id)sender { [self.principalonetext resignfirstresponder]; [self.rateonetext resignfirstresponder]; [self.principaltwotext resignfirstresponder]; [self.ratetwotext resignfirstresponder]; [self.principalthreetext resignfirstresponder]; [self.ratethreetext resignfirstresponder]; } @end
graphviewcontroller.h
#import <uikit/uikit.h> #import "coreplot-cocoatouch.h" #import "dataviewcontroller.h" #import <quartzcore/quartzcore.h> @interface graphviewcontroller : uiviewcontroller <cptplotdatasource> @property (weak, nonatomic) nsstring *principalone; @property (weak, nonatomic) nsstring *rateone; @property (weak, nonatomic) nsstring *principaltwo; @property (weak, nonatomic) nsstring *ratetwo; @property (weak, nonatomic) nsstring *principalthree; @property (weak, nonatomic) nsstring *ratethree; - (ibaction)foundswipe:(id)sender; @end
and graphviewcontroller.m
#import "graphviewcontroller.h" @interface graphviewcontroller () @end @implementation graphviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // transfer values text boxes in data scene data holders in graph scene self.principalone = ((dataviewcontroller *)self.presentingviewcontroller).principalonetext.text; self.rateone = ((dataviewcontroller *)self.presentingviewcontroller).rateonetext.text; self.principaltwo= ((dataviewcontroller *)self.presentingviewcontroller).principaltwotext.text; self.ratetwo = ((dataviewcontroller *)self.presentingviewcontroller).ratetwotext.text; self.principalthree = ((dataviewcontroller *)self.presentingviewcontroller).principalthreetext.text; self.ratethree = ((dataviewcontroller *)self.presentingviewcontroller).ratethreetext.text; //create graph upon loading //initialise host-view cptgraphhostingview *hostview = [[cptgraphhostingview alloc] initwithframe:self.view.frame]; [self.view addsubview:hostview]; //initialize graph cptxygraph *graph = [[cptxygraph alloc] initwithframe:self.view.bounds]; hostview.hostedgraph = graph; graph.paddingtop = 25.0f; //initialize plot space cptxyplotspace *plotspace = (cptxyplotspace*) graph.defaultplotspace; //[plotspace setxrange:[cptplotrange plotrangewithlocation:cptdecimalfromfloat(0) length:cptdecimalfromfloat(16)]]; //[plotspace setyrange:[cptplotrange plotrangewithlocation:cptdecimalfromfloat(80) length:cptdecimalfromfloat(140)]]; //initialize plots (1,2, , 3) cptscatterplot *plot1 = [[cptscatterplot alloc] initwithframe:cgrectzero]; plot1.identifier = @"investment #1"; cptcolor *plot1color = [cptcolor redcolor]; cptscatterplot *plot2 = [[cptscatterplot alloc] initwithframe:cgrectzero]; plot2.identifier = @"investment #2"; cptcolor *plot2color = [cptcolor bluecolor]; cptscatterplot *plot3 = [[cptscatterplot alloc] initwithframe:cgrectzero]; plot3.identifier = @"investment #3"; cptcolor *plot3color = [cptcolor greencolor]; //plot 4 way make sure automatic ranges include y=0 cptscatterplot *plot4 = [[cptscatterplot alloc] initwithframe:cgrectzero]; plot4.identifier = @"placeholder"; //define datasource plot1.datasource = self; plot2.datasource = self; plot3.datasource = self; plot4.datasource = self; //combine elements graph method call [graph addplot:plot1 toplotspace:graph.defaultplotspace]; [graph addplot:plot2 toplotspace:graph.defaultplotspace]; [graph addplot:plot3 toplotspace:graph.defaultplotspace]; [graph addplot:plot4 toplotspace:graph.defaultplotspace]; //graph title , theme setup //graph.title = @"future values"; //graph.titleplotareaframeanchor = cptrectanchortop; cpttheme *selectedtheme = [cpttheme themenamed:kcptdarkgradienttheme]; [graph applytheme:selectedtheme]; //auto-formats ranges of x , y coordinates depending on data used [plotspace scaletofitplots:[nsarray arraywithobjects:plot1, plot2, plot3, plot4, nil]]; cptmutableplotrange *xrange = [plotspace.xrange mutablecopy]; [xrange expandrangebyfactor:cptdecimalfromcgfloat(1.1f)]; plotspace.xrange = xrange; cptmutableplotrange *yrange = [plotspace.yrange mutablecopy]; [yrange expandrangebyfactor:cptdecimalfromcgfloat(1.1f)]; plotspace.yrange = yrange; //styles , symbols //plot1 cptmutablelinestyle *plot1linestyle = [plot1.datalinestyle mutablecopy]; plot1linestyle.linewidth = 2.5; plot1linestyle.linecolor = plot1color; plot1.datalinestyle = plot1linestyle; cptmutablelinestyle *plot1symbollinestyle = [cptmutablelinestyle linestyle]; plot1linestyle.linecolor = plot1color; cptplotsymbol *plot1symbol = [cptplotsymbol ellipseplotsymbol]; plot1symbol.fill = [cptfill fillwithcolor:plot1color]; plot1symbol.linestyle = plot1symbollinestyle; plot1symbol.size = cgsizemake(6.0f, 6.0f); plot1.plotsymbol = plot1symbol; //plot2 style cptmutablelinestyle *plot2linestyle = [plot2.datalinestyle mutablecopy]; plot2linestyle.linewidth = 1.0; plot2linestyle.linecolor = plot2color; plot2.datalinestyle = plot2linestyle; cptmutablelinestyle *plot2symbollinestyle = [cptmutablelinestyle linestyle]; plot2symbollinestyle.linecolor = plot2color; cptplotsymbol *plot2symbol = [cptplotsymbol starplotsymbol]; plot2symbol.fill = [cptfill fillwithcolor:plot2color]; plot2symbol.linestyle = plot2symbollinestyle; plot2symbol.size = cgsizemake(6.0f, 6.0f); plot2.plotsymbol = plot2symbol; //plot3 style cptmutablelinestyle *plot3linestyle = [plot3.datalinestyle mutablecopy]; plot3linestyle.linewidth = 2.0; plot3linestyle.linecolor = plot3color; plot3.datalinestyle = plot3linestyle; cptmutablelinestyle *plot3symbollinestyle = [cptmutablelinestyle linestyle]; plot3symbollinestyle.linecolor = plot3color; cptplotsymbol *plot3symbol = [cptplotsymbol diamondplotsymbol]; plot3symbol.fill = [cptfill fillwithcolor:plot3color]; plot3symbol.linestyle = plot3symbollinestyle; plot3symbol.size = cgsizemake(6.0f, 6.0f); plot3.plotsymbol = plot3symbol; //axis styles , setup cptmutabletextstyle *axistitlestyle = [cptmutabletextstyle textstyle]; axistitlestyle.color = [cptcolor whitecolor]; axistitlestyle.fontname = @"helvetica-bold"; axistitlestyle.fontsize = 12.0f; cptmutablelinestyle *axislinestyle = [cptmutablelinestyle linestyle]; axislinestyle.linewidth = 2.0f; axislinestyle.linecolor = [cptcolor whitecolor]; cptmutabletextstyle *axistextstyle = [[cptmutabletextstyle alloc] init]; axistextstyle.color = [cptcolor whitecolor]; axistextstyle.fontname = @"helvetica-bold"; axistextstyle.fontsize = 11.0f; cptmutablelinestyle *ticklinestyle = [cptmutablelinestyle linestyle]; ticklinestyle.linecolor = [cptcolor whitecolor]; ticklinestyle.linewidth = 2.0f; cptmutablelinestyle *gridlinestyle = [cptmutablelinestyle linestyle]; ticklinestyle.linecolor = [cptcolor blackcolor]; ticklinestyle.linewidth = 1.0f; //x axis setup cptxyaxisset *axisset = (cptxyaxisset *) hostview.hostedgraph.axisset; cptaxis *x = axisset.xaxis; x.title = @"number of years"; x.titletextstyle = axistitlestyle; x.titleoffset = 15.0f; x.axislinestyle = axislinestyle; x.labelingpolicy = cptaxislabelingpolicyautomatic; x.labeltextstyle = axistextstyle; x.preferrednumberofmajorticks = 15; x.majorticklinestyle = axislinestyle; x.majorticklength = 4.0f; x.tickdirection = cptsignnegative; //y axis setup cptaxis *y = axisset.yaxis; y.title = @"value"; y.titletextstyle = axistitlestyle; y.titleoffset = -20.0f; y.axislinestyle = axislinestyle; y.majorgridlinestyle = gridlinestyle; y.labelingpolicy = cptaxislabelingpolicyautomatic; y.labeltextstyle = axistextstyle; y.labeloffset = 16.0f; y.majorticklinestyle = axislinestyle; y.preferrednumberofmajorticks = 10; y.majorticklength = 4.0f; y.minorticklength = 2.0f; y.tickdirection = cptsignpositive; //create legend graph.legend = [cptlegend legendwithgraph:graph]; graph.legendanchor = cptrectanchortop; graph.legend.fill = [cptfill fillwithcolor:[cptcolor lightgraycolor]]; graph.legenddisplacement = cgpointmake(-200.0f, -50.0f); } -(nsuinteger) numberofrecordsforplot:(cptplot *)plot { return 15; } -(nsnumber *) numberforplot:(cptplot *)plot field:(nsuinteger)fieldenum recordindex:(nsuinteger)idx { int x = idx; float principal1 = [self.principalone floatvalue]; float interest1 = [self.rateone floatvalue]/100; float power1 = powf((1+(interest1)), x); float principal2 = [self.principaltwo floatvalue]; float interest2 = [self.ratetwo floatvalue]/100; float power2 = powf((1+(interest2)),x); float principal3 = [self.principalthree floatvalue]; float interest3 = [self.ratethree floatvalue]/100; float power3 = powf((1+(interest3)), x); if (fieldenum == cptscatterplotfieldx) { return [nsnumber numberwithint:x]; } else if(fieldenum == cptscatterplotfieldy){ if([plot.identifier isequal:@"investment #1"]) { return [nsnumber numberwithfloat:principal1*power1]; } else if([plot.identifier isequal:@"investment #2"]) { return [nsnumber numberwithfloat:principal2 * power2]; } else if([plot.identifier isequal:@"investment #3"]) { return [nsnumber numberwithfloat:principal3 * power3]; } else if ([plot.identifier isequal:@"placeholder"]) { return [nsnumber numberwithfloat:0]; } } return [nsnumber numberwithfloat:0]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (ibaction)foundswipe:(id)sender { [self dismissviewcontrolleranimated:yes completion:nil]; } @end
am missing something? why there difference between xcode ipad simulator graph , 1 displays on actual device? or advice welcome.
Comments
Post a Comment