Add labels for track ball

27 Oct 2020 / 1 minute to read

We can add labels for track ball to show the corresponding values. In order to add labels for the trackball, you need to subscribe the event OnSparklineMouseMove and you can get the following data’s from event argument.

<Page.DataContext>

	<local:UsersViewModel/>

</Page.DataContext>

<Syncfusion:SfLineSparkline ShowTrackBall="True" OnSparklineMouseMove="SfLineSparkline_OnSparklineMouseMove" x:Name="sparkline" ItemsSource="{Binding UsersList}" YBindingPath="NoOfUsers" >

</Syncfusion:SfLineSparkline>
ContentPresenter info;

        private void SfLineSparkline_OnSparklineMouseMove(object src, SparklineMouseMoveEventArgs args)

        {

            if (!args.RootPanel.Children.Contains(info))

            {

                info=new ContentPresenter();

                args.RootPanel.Children.Add(info);

                TextBlock.SetForeground(info, new SolidColorBrush(Colors.Red)); 
                
                TextBlock.SetFontSize(info, 25); 
            }

            info.Content = args.Value.Y;

            info.Arrange(new Rect(args.Coordinate.X,args.Coordinate.Y,info.ActualWidth,info.ActualHeight));

        }

Following is the snapshot for track ball labels,

custom label in Sparkline track ball