Articles in this section
Category / Section

How to show tooltip on Xamarin.Forms Chart axis label click?

1 min read

This article explains how to programmatically show the tooltip when tapping on the Xamarin Chart axis label.

You can show the tooltip programmatically with the help of axis LabelClicked event and Show method of ChartTooltipBehavior as per the following code snippet and also you can download the complete sample from this GitHub location.


XAML

 <chart:SfChart.PrimaryAxis> 
       <chart:CategoryAxis LabelClicked ="CategoryAxis_LabelClicked" /> 
</chart:SfChart.PrimaryAxis>  
 
<chart:SfChart.Series>
      <chart:ColumnSeries EnableTooltip="True" ItemsSource="{Binding ColumnData}" XBindingPath="XValue" YBindingPath="YValue" />
</chart:SfChart.Series>
                
<chart:SfChart.ChartBehaviors>
    <chart:ChartTooltipBehavior x:Name="tooltip"/>
</chart:SfChart.ChartBehaviors>
 

 

C#

private void CategoryAxis_LabelClicked(object sender, LabelClickedEventArgs e)
{
            var datapoints = series.GetDataPoints(e.Position, e.Position, chart.SeriesBounds.Top, chart.SeriesBounds.Bottom);
 
            if (datapoints.Count > 0)
            {
                ChartModel data = datapoints[0] as ChartModel;
                float xPoint = (float)chart.ValueToPoint(chart.PrimaryAxis, e.Position);
                float yPoint = (float)chart.ValueToPoint(chart.SecondaryAxis, data.YValue);
                tooltip.Show(xPoint, yPoint, true);
            }
}

 

Note:

Show method is available for Android and iOS platforms only. It will not work for UWP platform.

  

Gif

 

Show tooltip on Xamarin.Forms Chart axis label click

 

See also

https://help.syncfusion.com/xamarin/charts/tooltip#methods

https://help.syncfusion.com/xamarin/charts/how-to/get-the-data-point-collection-based-on-region

Conclusion

I hope you enjoyed learning about how to show tooltip on Xamarin.Forms Chart axis label click.

You can refer to our Xamarin Chart’s feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin Chart Documentation to understand how to present and manipulate data.

For current customers, you can check out our Xamarin components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Xamarin Chart and other Xamarin components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied