2

我有一张带有 3 的图表SChartLineSeries。我想同时显示 3 个同时目标点(来自与他的系列对应的十字准线)。

就像我在这张带有 dataPoints 的图片上一样,但我希望它与 Crosshairs 在同一个 X 位置上。

在此处输入图像描述

我怎样才能做到这一点?我试图识别委托方法中的“长按”事件,但我不知道该怎么做。

使用十字准线,我只有这个:

在此处输入图像描述

编辑

我试过了:

- (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint
{
    for (SChartLineSeries *serie in chart.series) {
        for (SChartDataPoint *dp in serie.dataSeries.dataPoints){
            if (dp.xValue == dataPoint.xValue){
                dp.selected = YES;
                serie.crosshairEnabled = YES;
                serie.style.selectedPointStyle.color = [UIColor blackColor];
                serie.style.selectedPointStyle.radius = [NSNumber numberWithInt:8];
                serie.style.selectedPointStyle.showPoints = YES;
            }
        }
    }
}

并将对象 ' SChartCrosshair' 子类化,我识别出 ' ' 上的长按事件crosshairChartGotLongPressAt

4

1 回答 1

0

在 ShinobiControls 团队支持的帮助下,我已经完成了它。

SChartCrosshair我子类化的“”上,我必须遍历与“ Crosshair”X 触摸位置匹配的点,并将数学运算的点添加到数组中以便在“ drawCrosshairLines”中使用它们。为此,我使用了点的像素版本,通过一种理解SChartAxis对象的方法:' pixelValueForDataValue'。

我也在图表上画了一条垂直线。

@implementation CustomCrossHair

-(void)drawCrosshairLines
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    SChartDataPoint *firstDataPixelPoint = arrayPixelPoints[0];
    double xFirst = [firstDataPixelPoint.xValue doubleValue];

    CGContextMoveToPoint(context,xFirst, 0.f);

    CGContextAddLineToPoint(context,xFirst, self.chart.canvas.glView.frame.size.height);

    for (SChartDataPoint *dataPixelPoint in arrayPixelPoints){
        double yVal = [dataPixelPoint.yValue doubleValue];
        double xVal = [dataPixelPoint.xValue doubleValue];

        CGRect rectangle = CGRectMake(xVal,yVal, 7, 7);
        CGContextAddEllipseInRect(context, rectangle);
    }

    CGContextStrokePath(context);
}


-(void)moveToPosition:(SChartPoint)coords andDisplayDataPoint:(SChartPoint)dataPoint fromSeries:(SChartCartesianSeries *)series andSeriesDataPoint:(id<SChartData>)dataseriesPoint
{
    [super moveToPosition:coords andDisplayDataPoint:dataPoint fromSeries:series andSeriesDataPoint:dataseriesPoint];
    arrayPixelPoints = [NSMutableArray array];
    SChartDataPoint *dataSPoint = dataseriesPoint;
    int i = 0;
    for (SChartLineSeries *serie in self.chart.series){
        i++;
        for (SChartDataPoint *dp in serie.dataSeries.dataPoints){
            if ([dp.xValue doubleValue] == [dataSPoint.xValue doubleValue]){
                float yPixel = [self.chart.yAxis pixelValueForDataValue:dp.yValue];
                float xPixel = [self.chart.xAxis pixelValueForDataValue:dp.xValue];

                SChartDataPoint *dataPointPixel = [[SChartDataPoint alloc] init];
                dataPointPixel.xValue = [NSNumber numberWithFloat:xPixel];
                dataPointPixel.yValue = [NSNumber numberWithFloat:yPixel];

                [arrayPixelPoints addObject:dataPointPixel];
            }
        }
    }

    if (i == self.chart.series.count) [self drawCrosshairLines];
}
于 2015-04-22T07:53:50.360 回答