ios - Core-Plot - get coordinates of parent view from x y values -
i have scatter plot , x,y values of point in plot. i'd add information on top of plot, can't seem parent view coordinates x y values. i've got following code question, values not correct : core plot: how present popover bar selected user
i have cptgraphhostingview *hostview;
located in uiview *statsview;
nsdecimal plotpoint[2]; nsnumber *plotxvalue = [distancearray objectatindex:index]; plotpoint[cptcoordinatex] = plotxvalue.decimalvalue; nsnumber *plotyvalue = [altitudearray objectatindex:index]; plotpoint[cptcoordinatey] = plotyvalue.decimalvalue; cptxyplotspace *plotspace = (cptxyplotspace *)self.hostview.hostedgraph.defaultplotspace; // convert data coordinates plot area coordinates cgpoint datapoint = [plotspace plotareaviewpointforplotpoint:plotpoint numberofcoordinates:2]; // convert plot area coordinates graph (and hosting view) coordinates datapoint = [self.hostview.hostedgraph convertpoint:datapoint fromlayer:self.hostview.hostedgraph.plotareaframe.plotarea]; // convert hosting view coordinates self.view coordinates (if needed) datapoint = [statsview convertpoint:datapoint fromview:self.hostview]; nslog(@"barwasselectedatrecordindex x: %@, y: %@", plotxvalue, plotyvalue); nslog(@"datapoint coordinates tapped: %@", nsstringfromcgpoint(datapoint));
this log gets printed
barwasselectedatrecordindex x: 2.002954100413836, y: 797.5011302303315
datapoint coordinates tapped: {442.67648899476842, 80323.113023033162}
update: turns out calling before plot setup, bogus numbers came from. unfortunately, calling after gets setup still doesn't give me right answer. closer, still wrong.
datapoint coordinates tapped: {109.55009099317836, 187.9865691006616}
update 2 hint, x coordinates aren't proportional expect graph values of 3,6,9,12,15 give coordinates of 32, 71, 109, 147, 186
Comments
Post a Comment