Core Plot - How to convert a touch point to a chart point in chart space with a log axis

I have a scatter plot with a linear y axis and a logarithmic x axis, all of which work fine. But when I try to convert the touch point to the coordinates of the space, I have problems.

I saw something like the following different places offered:

- (BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceUpEvent:(id)event atPoint:(CGPoint)point
{
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)space;

CPTScatterPlot *scatterPlot = [[[plotSpace graph] allPlots] objectAtIndex:0]; 
CGPoint plotAreaPoint = [[plotSpace graph] convertPoint:point toLayer:scatterPlot];

NSLog(@"PlotAreaPoint : %.1f, %.1f", plotAreaPoint.x, plotAreaPoint.y);

NSDecimal dataPoint[2];
NSDecimalNumber *xCoordinate, *yCoordinate;

[plotSpace plotPoint:dataPoint forPlotAreaViewPoint:plotAreaPoint];

xCoordinate = [NSDecimalNumber decimalNumberWithDecimal:dataPoint[0]];
yCoordinate = [NSDecimalNumber decimalNumberWithDecimal:dataPoint[1]];

NSLog(@"DataPoint : %.1f, %.1f", [xCoordinate floatValue], [yCoordinate floatValue]);

return YES;
}

When I run this, plotAreaPoint seems right and yCoordinate seems right. xThe coordination is correct if I touch the left edge (5.0) or the right edge (500.0), but behaves like a linear axis if I touch the middle. If I touch the middle, I get 250.0 or so, instead of 50.0. Am I missing something, or is there another way to do this?

Thanks Tim

+3
source share
1

. , .

0

All Articles