ios - Plot annotations exactly on right side of tap -
ios - Plot annotations exactly on right side of tap -
i stuck in plotting annotation within graph. annotation coming @ respective x coordinate y coordinate not alining showing @ top need annotation placed @ tapped position.
-(void)scatterplot:(cptscatterplot *)plot plotsymbolwasselectedatrecordindex:(nsuinteger)idx { uiview *view = [self.graphview.superview viewwithtag:99]; if (view!=nil) { [view removefromsuperview]; } nsnumber *plotxvalue = [self numberforplot:plot field:cptscatterplotfieldx recordindex:idx]; nsnumber *plotyvalue = [self numberforplot:plot field:cptscatterplotfieldy recordindex:idx]; nsarray *anchorpoint = [nsarray arraywithobjects:plotxvalue, plotyvalue, nil]; cptgraph *graph = self.hostview.hostedgraph; cptxyplotspace *plotspace = (cptxyplotspace *)graph.defaultplotspace; cgpoint cgplotpoint = cgpointmake(plotxvalue.floatvalue, plotyvalue.floatvalue); cgpoint cgplotareapoint = [graph convertpoint:cgplotpoint tolayer:self.graphview.layer]; nsdecimal plotareapoint[2]; plotareapoint[cptcoordinatex] = cptdecimalfromfloat(cgplotareapoint.x); plotareapoint[cptcoordinatey] = cptdecimalfromfloat(cgplotareapoint.y); cptlayer *layer = [[cptlayer alloc] init]; layer.contents = (id)view; cgpoint datapoint = [plotspace plotareaviewpointforplotpoint:plotareapoint numberofcoordinates:2]; nslog(@"datapoint (cgpoint) coordinates tapped: %@",nsstringfromcgpoint(datapoint)); if ([self.graphview.superview viewwithtag:99]) { [[self.graphview.superview viewwithtag:99] removefromsuperview]; } //cgrect graphframe = self.graphview.frame; //a view add together image , annotation uiview *selectedpointdetails = [[uiview alloc] initwithframe:cgrectmake(datapoint.x,datapoint.y, 38.0, 27.0)]; selectedpointdetails.tag = 99; uiimageview *annotationimage = [[uiimageview alloc] initwithframe:cgrectmake(0.0, 0.0, selectedpointdetails.frame.size.width, selectedpointdetails.frame.size.height)]; annotationimage.image = [uiimage imagenamed:@"popup@2x.png"]; [selectedpointdetails addsubview:annotationimage]; uilabel *annotationvalue = [[uilabel alloc] initwithframe:cgrectmake(0.0, 0.0, 38.0, 20.0)]; annotationvalue.textcolor = [uicolor whitecolor]; annotationvalue.textalignment = nstextalignmentcenter; annotationvalue.text = [nsstring stringwithformat:@"%0.2f",[plotyvalue floatvalue]]; nslog(@"plotyvalue %@", plotyvalue); annotationvalue.font = [uifont fontwithname:nil size:10.0]; [selectedpointdetails addsubview:annotationvalue]; [self.graphview.superview addsubview:selectedpointdetails]; [self.graphview.superview bringsubviewtofront:selectedpointdetails]; }
the datapoint received plot space in coordinate space of plot area layer. convert graph layer coordinates match hosting view coordinates. there, convert parent view's coordinate space , utilize point anchor label.
ios objective-c core-plot
Comments
Post a Comment