我有一张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
'。
答案 0 :(得分:0)
我已经在ShinobiControls团队支持的帮助下完成了它。
在'SChartCrosshair
'I sublassed上,我不得不遍历与触摸的'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];
}