objective c - Data points not showing when using Core Plot -
i'm making graph ios app, using core plot 1.0 , ios 5.1.
i've went through tutorials can find core plot , have showing on graph except scatterplot data itself...
can't post screenshot because of reputation here link one: http://francoismaillet.com/coreplot_problem.png
i'm using numberofrecordsforplot , numberforplot methods simplescatterplot.m example. generatedata method generates numbers between 0 , 2.
i've been turning in circles while , appreciated.
here's class interface:
interface pricechartviewcontroller : uiviewcontroller <cptplotdatasource, cptscatterplotdelegate>{ nsarray *plotdata; }
here's viewdidload method:
- (void)viewdidload { [super viewdidload]; [self generatedata]; cptgraphhostingview *hostingview = [[cptgraphhostingview alloc] initwithframe:self.view.bounds]; cptxygraph *graph = [[[cptxygraph alloc] initwithframe:self.view.bounds] autorelease]; cpttheme *theme = [cpttheme themenamed:kcptdarkgradienttheme]; [graph applytheme:theme]; hostingview.hostedgraph = graph; //hostingview.collapseslayers = yes; graph.paddingleft = 15.0; graph.paddingtop = 40.0; graph.paddingright = 15.0; graph.paddingbottom = 40.0; // plotspace graph cptxyplotspace *plotspace = (cptxyplotspace *)graph.defaultplotspace; plotspace.xrange = [cptplotrange plotrangewithlocation:cptdecimalfromfloat(-2) length:cptdecimalfromfloat(4)]; plotspace.yrange = [cptplotrange plotrangewithlocation:cptdecimalfromfloat(-2) length:cptdecimalfromfloat(4)]; [graph addplotspace:plotspace]; // axisset graph cptxyaxisset *axisset = (cptxyaxisset *)graph.axisset; cptmutablelinestyle *majorgridlinestyle = [cptmutablelinestyle linestyle]; majorgridlinestyle.linewidth = 1.0f; majorgridlinestyle.linecolor = [[cptcolor whitecolor] colorwithalphacomponent:0.75f]; cptmutablelinestyle *minorgridlinestyle = [cptmutablelinestyle linestyle]; minorgridlinestyle.linewidth = 1.0f; minorgridlinestyle.linecolor = [[cptcolor whitecolor] colorwithalphacomponent:0.25f]; cptxyaxis *x = axisset.xaxis; x.title = @"x axis"; x.titleoffset = -20.0f; x.titlelocation = cptdecimalfromfloat(30.0f); x.majorgridlinestyle = majorgridlinestyle; x.minorgridlinestyle = minorgridlinestyle; x.majorintervallength = cptdecimalfrominteger(1); x.minorticksperinterval = 0.5; x.plotspace = plotspace; cptxyaxis *y = axisset.yaxis; y.majorintervallength = cptdecimalfrominteger(1); y.minorticksperinterval = 0.5; //y.orthogonalcoordinatedecimal = cptdecimalfrominteger(-0.5); //y.preferrednumberofmajorticks = 8; y.plotspace = plotspace; // create scatterplot cptscatterplot *datasourcelineplot = [[cptscatterplot alloc] init]; datasourcelineplot.identifier = @"alltests"; cptmutablelinestyle *linestyle = [[datasourcelineplot.datalinestyle mutablecopy] autorelease]; //linestyle.miterlimit = 1.0f; linestyle.linewidth = 3.0f; linestyle.linecolor = [cptcolor bluecolor]; datasourcelineplot.datalinestyle = linestyle; datasourcelineplot.datasource = self; [graph addplot:datasourcelineplot]; // blue gradient cptcolor *areacolor1 = [cptcolor colorwithcomponentred:0.3 green:0.3 blue:1.0 alpha:0.8]; cptgradient *areagradient1 = [cptgradient gradientwithbeginningcolor:areacolor1 endingcolor:[cptcolor clearcolor]]; areagradient1.angle = -90.0f; cptfill *areagradientfill = [cptfill fillwithgradient:areagradient1]; datasourcelineplot.areafill = areagradientfill; datasourcelineplot.areabasevalue = [[nsdecimalnumber zero] decimalvalue]; // auto scale plot space fit plot data // extend ranges 30% neatness [plotspace scaletofitplots:[nsarray arraywithobjects:datasourcelineplot, nil]]; cptmutableplotrange *xrange = [[plotspace.xrange mutablecopy] autorelease]; cptmutableplotrange *yrange = [[plotspace.yrange mutablecopy] autorelease]; [xrange expandrangebyfactor:cptdecimalfromdouble(1.3)]; [yrange expandrangebyfactor:cptdecimalfromdouble(1.3)]; plotspace.xrange = xrange; plotspace.yrange = yrange; graph.legend = [cptlegend legendwithgraph:graph]; graph.legend.textstyle = x.titletextstyle; graph.legend.fill = [cptfill fillwithcolor:[cptcolor darkgraycolor]]; graph.legend.borderlinestyle = x.axislinestyle; graph.legend.cornerradius = 5.0; graph.legend.swatchsize = cgsizemake(25.0, 25.0); graph.legendanchor = cptrectanchorbottom; graph.legenddisplacement = cgpointmake(0.0, 12.0); [self setview:hostingview]; }
remove line:
[graph addplotspace:plotspace];
you've positioned axes using 1 plot space , added plot another. if default plot space, should work fine. don't see need 2 different plot spaces in simple graph this.
Comments
Post a Comment