How to show the trackball on load time in Xamarin.Forms Charts?
This article explains how to programmatically show the trackball when loading the Xamarin Cchart.
You can show the trackball programmatically with the help of chart SeriesRendered event and Show method of ChartTrackballBehavior as shown in the following code sample.
XAML
<chart:SfChart SeriesRendered="Chart_SeriesRendered" VerticalOptions="FillAndExpand"> … <chart:SfChart.ChartBehaviors> <chart:ChartTrackballBehavior x:Name="trackball"/> </chart:SfChart.ChartBehaviors> </chart:SfChart>
Either you can show the trackball, using the pixel position or axis values by anyone of the following solutions:
Solution 1: Using the pixel values.
You can show the trackball by directly passing the pixel position to the Show method.
C#
private void Chart_SeriesRendered(object sender, EventArgs e) { SfChart chart = sender as SfChart; trackball.Show(567, 333); }
Solution 2: Using the data point.
You can show the trackball by converting the axis data points to the pixel values by using the ValueToPoint method and passing that converted pixel value to the Show method.
C#
private void Chart_SeriesRendered(object sender, EventArgs e) { SfChart chart = sender as SfChart; float xposition = (float)chart.ValueToPoint(chart.PrimaryAxis, new DateTime(2000, 4, 19).ToOADate()); float yposition = (float)chart.ValueToPoint(chart.SecondaryAxis, 86); trackball.Show(xposition,yposition); }
Output
Conclusion
I hope you enjoyed learning about how to show the trackball on load time in Xamarin.Forms Charts.
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!