私は@ Wingzeroの提案を考えて方法を見つけましたが、大きな違いはタッチポイントを使って "マーカー"かどうかを調べることでした。その正しい方法かどうかはわからないんだけど、解決策はある、
-(void)chartValueSelected:(ChartViewBase *)chartView entry:(ChartDataEntry *)entry dataSetIndex:(NSInteger)dataSetIndex highlight:(ChartHighlight *)highlight{
//-----------------------------------------------------getting recognizer value
UIGestureRecognizer *recognisedGesture = [chartView.gestureRecognizers objectAtIndex:0];
CGPoint poinOfTouch =[recognisedGesture locationInView:chartView];
CGPoint poinOfMarker =[chartView getMarkerPositionWithEntry:entry highlight:highlight];
if (check if the chartview is BarChartView and if true) {
//-----------------------------------------------------If you want to detect touch/tap only on barchartview's bars
if (poinOfTouch.y > poinOfMarker.y) {
NSLog(@"within the bar area!");
}
else{
NSLog(@"Outside the bar area!");
}
}
else
{
//-----------------------------------------------------If you want to detect touch/tap only on linechartView's markers
//-----------------------------------------------------creating two arrays of x and y points(possible nearby points of touch location)
NSMutableArray *containingXValue = [[NSMutableArray alloc]init];
NSMutableArray *containingYValue = [[NSMutableArray alloc]init];
for (int i =0 ; i<5; i++) {
int roundedX = (poinOfMarker.x + 0.5);
int sumXValuesPositive = roundedX+i;
[containingXValue addObject:[NSNumber numberWithInt:sumXValuesPositive]];
int sumXValuesNegative = roundedX-i;
[containingXValue addObject:[NSNumber numberWithInt:sumXValuesNegative]];
int roundedY = (poinOfMarker.y + 0.5);
int sumYValuesPositive = roundedY+i;
[containingYValue addObject:[NSNumber numberWithInt:sumYValuesPositive]];
int sumYValuesNegative = roundedY-i;
[containingYValue addObject:[NSNumber numberWithInt:sumYValuesNegative]];
}
//-----------------------------------------------------------------------------------------------------------------------------------------
int roundXPointTOuched = (poinOf.x + 0.5);
int roundYPointTOuched = (poinOf.y + 0.5);
//-----------------------------------------------------check if touchpoint exists in the arrays of possible points
if ([containingXValue containsObject:[NSNumber numberWithInt:roundXPointTOuched]] && [containingYValue containsObject:[NSNumber numberWithInt:roundYPointTOuched]])
{
// continue, the click is on marker!!!!
}
else
{
// stop, the click is not on marker!!!!
}
//-----------------------------------------------------------------------------------------------------------------------------------------
}
}
}
編集:これと同じ状況が棒グラフのために発生した場合、最初のソリューションは今、唯一の折れ線グラフのために適用しました上記のコード自体でそれを処理することができます。
男、私はしばらく前から走っていて、ポジティブなリードを得るのに本当に素晴らしいと感じています。この問題の方向性はまだありません。これが私のような人にとって朗報です。
P.S.私はちょうど確かめるために答えとしてこれをマークしています、それは必要に達する:)。ありがとうございました
私はハイライトしたくありません。ユーザーがチャート内のドット(プロッティングポイント)をタップし、外部で発生するタップを無視すると、別のビューにプッシュする必要がありますポイント。 –
あなたは「プロットされたポイントだけをクリックすることを許可する方法」を要求しています。これはハイライトに関連していますか?あなたはそのドットをタップして強調表示されます。デフォルトでは、これがサポートされています。デリゲート 'chartValueSelected'を使ってどのデータがハイライト表示されているかを知るだけです。回答が更新されました。 – Wingzero
しかし、「最も近いデータセットとxインデックスを計算する」はどのように計算されますか?私は、コードを使用して、 'float xVal = [lineChartView getValueByTouchPointWithPt:[ジェスチャーlocationInView:lineChartView]軸:AxisDependencyLeft]というchartValueSelectedのタッチポイントを取得しました。x; ' もっと具体的に教えてください。どのように&どこで私は最大距離を定義する必要がありますか?私はできること全てを試しましたが、それを働かせることができませんでした、少し説明できますか? –