Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
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
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
In [SfCartesianChart](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.SfCartesianChart.html), tooltip and data label templates do not bind directly to your business model because these elements are generated by the chart at runtime and often represent calculated points. As a result, the chart provides its own binding context containing the necessary metadata. For tooltips this context is [TooltipInfo]https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.TooltipInfo.html), and for data labels it is [ChartDataLabel](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.Charts.ChartDataLabel.html). Both expose an Item property that points back to your original business model when a direct mapping exists. With .NET 9 compiled bindings, set **x:DataType="chart:TooltipInfo"** for tooltip templates and **x:DataType="chart:ChartDataLabel"** for data label templates, then bind through Item. If you need a specific field from your model, bind to Item and use a value converter to extract the desired property.

`Ahead-of-Time (AOT)` compilation converts Intermediate Language to native code at build time to improve startup and runtime performance. AOT commonly ships together with linker trimming in Release configurations to reduce app size.

Because Release builds enable trimming, members referenced only from XAML can be removed unless explicitly preserved. To ensure your bindings work in Release, reference your value converter from XAML and preserve your ViewModel, business model, and converter types. This prevents the linker from removing properties that your tooltip or data label templates access through Item.

{% tabs %}

{% highlight xaml %}

<chart:SfCartesianChart>
<chart:SfCartesianChart.Resources>
<local:ValueConverter x:Key="valueConverter" />

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

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

<chart:SplineAreaSeries x:Name="series"
ItemsSource="{Binding ChartData}"
XBindingPath="WeekNumber"
YBindingPath="Planned"
EnableTooltip="True"
ShowDataLabels="True"
LabelTemplate="{StaticResource labelTemplate}"
TooltipTemplate="{StaticResource tooltiptemplate}">
</chart:SplineAreaSeries>

</chart:SfCartesianChart>

{% endhighlight %}


{% highlight C# %}

public class ValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is WeekPlan weekPlan ? weekPlan.Planned : value;
}

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

{% endhighlight %}

{% endtabs %}

## See also

[Why Tooltip and DataLabel Are Missing in Release Mode .NET MAUI Chart?](https://support.syncfusion.com/kb/article/21677/why-tooltip-and-datalabel-are-not-showing-in-release-mode-in-net-maui-sfcartesianchart)
1 change: 1 addition & 0 deletions maui-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
<li><a href="/maui/cartesian-charts/Add-custom-labels">Add custom labels to the chart axis</a></li>
<li><a href="/maui/cartesian-charts/Customize-each-chart-axis-label">Customize each chart axis label using the callback event</a></li>
<li><a href="/maui/cartesian-charts/Get-the-data-point-collection-based-on-region">Get the data point collection based on region</a></li>
<li><a href="/maui/cartesian-charts/display-tooltip-and-data-labels-in-release-mode">Display tooltip and data labels in release mode</a></li>
</ul>
</li>
</ul>
Expand Down