Xuni User Guide > Xuni Controls > FlexChart > Features > Hit Test |
The HitTest()
method is used to determine X and Y coordinates, as well as the index of a point on the FlexChart where the user taps. This method is helpful in scenarios such as displaying tooltips that lie outside the series of the FlexChart.
The following code examples demonstrate how to define the chart_Tapped
event. This event invokes the HitTest()
method to retrieve the information of the tapped point in the FlexChart region and displays it in the chart footer.
chart_Tapped
event.
hitTest
of type FlexChartHitTestInfo
to store the information of the HitPoint
.
HitTest()
method to retrieve the information of the tapped point.
HitPoint
information in the chart footer.C# |
Copy Code |
---|---|
static void chart_Tapped(object sender, Xuni.Xamarin.Core.Events.XuniTappedEventArgs e) { // Invoke HitTest to retrieve HitPoint information FlexChartHitTestInfo hitTest = chart.HitTest(e.HitPoint); // Display HitPoint information in the chart footer chart.FooterText = "Point Index = " + hitTest.PointIndex.ToString() + "\n X Value = " + hitTest.XValue.ToString() + "\n Y Value = " + hitTest.YValue.ToString(); } |
Tapped
event handler on FlexChart as shown in the code below.
Note: In this topic FlexChart is declared as a public static member, outside the GetChartControl() method definition to make it accessible to the chart_Tapped event. |
C# |
Copy Code |
---|---|
//Set Tapped event handler on chart
chart.Tapped += chart_Tapped; |
chart_Tapped
in the C# code behind of the Forms XAML Page.
hitTest
of type FlexChartHitTestInfo
to store the information of the HitPoint
.
HitTest
method to retrieve the information of the tapped point.
HitPoint
information in the chart footer.C# |
Copy Code |
---|---|
void flexChart_Tapped(object sender, Xuni.Xamarin.Core.Events.XuniTappedEventArgs e) { // Invoke HitTest to retrieve HitPoint information FlexChartHitTestInfo hitTest = chart.HitTest(e.HitPoint); // Display HitPoint information in the chart footer chart.FooterText = "Point Index = " + hitTest.PointIndex.ToString() + "\n X Value = " + hitTest.XValue.ToString() + "\n Y Value = " + hitTest.YValue.ToString(); } |
Tapped
event on FlexChart as shown in the code below.
XAML |
Copy Code |
---|---|
<xuni:FlexChart x:Name="chart" ItemsSource="{Binding Data}" ChartType="Column" Tapped="flexChart_Tapped" > <xuni:FlexChart.Series> <xuni:ChartSeries x:Name="Sales2014" Name="2014 Sales" Binding="Sales" ></xuni:ChartSeries> </xuni:FlexChart.Series> </xuni:FlexChart> |