Search code examples
ioschartsshinobi

Show multiple crosshair target circles on Shinobicharts with same X position ( iOS )


I have a chart with 3 SChartLineSeries. I would like to show 3 simultaneous target points (from the crosshair that corresponds to his serie) at the same time.

Like I have on this picture with dataPoints, but I would like have it on the same X position with Crosshairs.

enter image description here

How can I achieve that? I tried to recognize the 'long press' event in the delegate method, but I didn't figure out how to do it.

With crosshairs, I only have this:

enter image description here

EDIT:

Ive tried:

- (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;
            }
        }
    }
}

And subclassing the object 'SChartCrosshair' I recognize the long press event on 'crosshairChartGotLongPressAt'.


Solution

  • I already managed it, with the help of ShinobiControls team support.

    On the 'SChartCrosshair' I subclassed, I had to loop over the points that matched with the 'Crosshair' X position touched, and adding the ones that mathed to an array for using them in 'drawCrosshairLines'. For that, I used, the pixel version of the point, through a method that understands the SChartAxis object: 'pixelValueForDataValue'.

    I draw a vertical line on the chart as well.

    @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];
    }