We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Chart Tooltip, DataTemplate - from code c#

How can i create a  Tooltip Template from c sharp code behind ? in the doc's i only found a way  todo it in xaml

3 Replies

RR Raja Ramalingam Syncfusion Team February 15, 2023 10:32 AM UTC

Hello Andreas,

We have created the data template in the code behind and set it to the series ToolTipTemplate property as shown in the code snippet. We have also attached a sample for your reference.

dataTemplate = new DataTemplate(() =>


    VerticalStackLayout mainlayout = new VerticalStackLayout();

    mainlayout.BackgroundColor = Colors.Black;


    HorizontalStackLayout yearLayout = new HorizontalStackLayout();

    yearLayout.BackgroundColor = Colors.Black;


    Label yearLabel = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White, Text = "Year:" };

    Label year = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White};

    year.SetBinding(Label.TextProperty, "Item.Year");




    HorizontalStackLayout revenueLayout = new HorizontalStackLayout();

    revenueLayout.BackgroundColor = Colors.Black;


    Label revenueLabel = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White, Text = "Revenue:" };

    Label revenue = new Label() { Padding = 2, FontSize = 10, TextColor = Colors.White };

    revenue.SetBinding(Label.TextProperty, "Item.Revenue", stringFormat: "{0}$");







    return mainlayout;



areaSeries.TooltipTemplate = dataTemplate;


Best Regards,

Attachment: TooltipTemplateSample_f7d4c83e.zip

AN Andreas February 17, 2023 07:16 AM UTC

thank you, this works perfectly - maybe you can add this to the doc's as well for others to easily find  this

PR Preethi Rajakandham Syncfusion Team February 20, 2023 09:31 AM UTC


You're welcome, Andreas. Currently, we are working on improving our UG, and we will consider your feedback.

Note: If that post is helpful, please mark it as an answer so that other members can locate it more quickly.


Preethi R

Live Chat Icon For mobile
Up arrow icon