CorePlot "indexOfVisiblePointClosestToPlotAreaPoint" 给我错误的索引

CorePlot "indexOfVisiblePointClosestToPlotAreaPoint" giving me wrong index

目前我正在用两个数据图(图表上的两条线)绘制图表,当我单击一行“indexOfVisiblePointClosestToPlotAreaPoint”方法时,给我正确的索引,而另一行则给我错误的索引,甚至不是最接近的可见索引它 skipping/jumping 之间的多个点。例如:如果我点击索引号 20,它会跳转到 15 或 25,反之亦然。这是找到索引

的计算
-(NSUInteger)indexOfVisiblePointClosestToPlotAreaPoint:(CGPoint)viewPoint
{
    NSUInteger dataCount = self.cachedDataCount;
    CGPoint *viewPoints  = calloc(dataCount, sizeof(CGPoint));
    BOOL *drawPointFlags = calloc(dataCount, sizeof(BOOL));

    [self calculatePointsToDraw:drawPointFlags forPlotSpace:(CPTXYPlotSpace *)self.plotSpace includeVisiblePointsOnly:YES numberOfPoints:dataCount];
    [self calculateViewPoints:viewPoints withDrawPointFlags:drawPointFlags numberOfPoints:dataCount];

    NSInteger result = [self extremeDrawnPointIndexForFlags:drawPointFlags numberOfPoints:dataCount extremeNumIsLowerBound:YES];
    if ( result != NSNotFound ) {
        CGFloat minimumDistanceSquared = CPTNAN;
        for ( NSUInteger i = (NSUInteger)result; i < dataCount; ++i ) {
            if ( drawPointFlags[i] ) {
                CGFloat distanceSquared = squareOfDistanceBetweenPoints(viewPoint, viewPoints[i]);
                if ( isnan(minimumDistanceSquared) || (distanceSquared < minimumDistanceSquared)) {
                    minimumDistanceSquared = distanceSquared;
                    result                 = (NSInteger)i;
                }
            }
        }
    }

    free(viewPoints);
    free(drawPointFlags);

    return (NSUInteger)result;
}

您是否正在检查委托方法中传递的 plot 参数?如果 plotSymbolMarginForHitDetection 内有任何点,触摸将记录在最前面的图上。它甚至不会检查其他情节,除非前面的情节没有任何影响。两条线像这样靠得很近,您需要使用较小的命中余量来确保触摸记录在正确的绘图上。