Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions maui-toolkit-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<li><a href="/maui-toolkit/cartesian-charts/Add-custom-labels">Add custom labels to the chart axis</a></li>
<li><a href="/maui-toolkit/cartesian-charts/Customize-each-chart-axis-label">Customize each chart axis label using the callback event</a></li>
<li><a href="/maui-toolkit/cartesian-charts/Get-the-data-point-collection-based-on-region">Get the data point collection based on region</a></li>
<li><a href="/maui-toolkit/cartesian-charts/Display-tooltip-datalabels-in-release-mode">Display tooltip and datalabels in release mode</a></li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
layout: post
title: Show tooltip and datalabels in release mode | Syncfusion
description: Learn here all about displaying tooltip and datalabels in release mode in SfCartesianChart in Syncfusion® .NET MAUI Chart (SfCartesianChart) control.
platform: maui-toolkit
control: SfCartesianChart
documentation: ug
keywords: .NET MAUI chart tooltip, .NET MAUI chart data label, TooltipInfo Item binding, ChartDataLabel Item binding, Release mode trimming, Preserve attribute MAUI.
---

# Display tooltip and data labels in release mode

The binding context inside tooltip and data labels templates is not your model directly. These templates run in the scope of [TooltipInfo](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.TooltipInfo.html) and [ChartDataLabel](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartDataLabel.html), which expose an `Item` property that contains the actual data model from the charts [ItemsSource](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartSeries.html#Syncfusion_Maui_Charts_ChartSeries_ItemsSource). To read your model’s fields in a template, bind through Item or use a converter.


With .NET 9 compiled bindings, tooltip templates run with **x:DataType="chart:TooltipInfo"** and data label templates run with **x:DataType="chart:ChartDataLabel"**. Inside these templates, bind to the model via the Item property. Use a value converter to pull the required field from Item. In Release builds, trimming/AOT can remove XAML-only types, so preserve your ViewModel, Model, and the converter to keep these bindings working.


{% highlight xaml %}

<chart:SfCartesianChart>
.....
<chart:SfCartesianChart.Resources>

<DataTemplate x:Key="TooltipTemplate">
<StackLayout x:DataType="chart:TooltipInfo" Orientation="Vertical">
<Label Text="{Binding Item,
Converter={StaticResource TooltipConverter},
ConverterParameter=Planned,
StringFormat='Planned : {0}h'}"/>
</StackLayout>
</DataTemplate>

<DataTemplate x:Key="DataLabelTemplate">
<StackLayout x:DataType="chart:ChartDataLabel" Orientation="Vertical">
<Label Text="{Binding Item,
Converter={StaticResource TooltipConverter},
ConverterParameter=Planned,
StringFormat='Planned : {0}h'}" />
</StackLayout>
</DataTemplate>
</chart:SfCartesianChart.Resources>

<chart:SplineAreaSeries
....
TooltipTemplate="{StaticResource TooltipTemplate}"
ShowDataLabels="True"
LabelTemplate="{StaticResource DataLabelTemplate}" />
</chart:SfCartesianChart>

{% endhighlight %}


{% highlight C# %}

public class TooltipConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
// value is TooltipInfo.Item or ChartDataLabel.Item -> your Model
if (value is Model model && parameter?.ToString() == "Planned")
return model.Planned;

return value;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => value;
}

{% endhighlight %}

## See also

[How to display tooltip and data labels in release mode .NET MAUI SfCartesianChart](https://support.syncfusion.com/kb/article/21677/why-tooltip-and-datalabel-are-not-showing-in-release-mode-in-net-maui-sfcartesianchart)