Using core-plot, how can you convert the affected point to graph space?

I have a very simple graph on which I want to enable touch, I have the first part of the work:

plotSpace.delegate = self;

and method:

-(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point { NSLog(@"touched at: x: %fy: %f", point.x, point.y); } 

How to convert a dot to a graph space of my graph?

I can see the methods, but Im unsure about how to use them, doco, although large, does not describe them very well :)

Thanks a lot Mark

+4
source share
2 answers

I have to admit that I forgot about this question, thanks for Steve's answer.

I also decided to solve it, here is my implementation (im ext CPXYGraph )

 -(BOOL)plotSpace:(CPPlotSpace *)space shouldHandlePointingDeviceDownEvent:(id)event atPoint:(CGPoint)point { CPScatterPlot *plot = (CPScatterPlot*)[[self allPlots] objectAtIndex: 0]; CGPoint pointInPlotArea = [plot convertPoint:point toLayer:plot]; if ([plot containsPoint:pointInPlotArea]) { CPXYPlotSpace *plotSpace = (CPXYPlotSpace*)[self defaultPlotSpace]; NSDecimal touchDataPoint[2]; [plotSpace plotPoint:touchDataPoint forPlotAreaViewPoint:pointInPlotArea]; } } 

touchDataPoint then contains the coordinates that the user touched.

+2
source

This is what I use:

 NSDecimal plotPoint[2]; CPXYPlotSpace *xySpace = (CPXYPlotSpace *)space; [xySpace plotPoint:plotPoint forPlotAreaViewPoint:point]; NSlog(@"plotPoint = %@, %@", [[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateX]] intValue], [[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPCoordinateY]] doubleValue]); 

I would suggest that you can change CPXYPlotSpace to CPPlotSpace, and on my chart the plot space is CPXYPlotSpace, so the plotPoint: forPlotAreaViewPoint method takes an array of 2 NSDecimal values.

Also on my graph, the x values ​​are integers, and the y values ​​are doubled.

+6
source

Source: https://habr.com/ru/post/1316012/


All Articles