diff --git a/maui-toolkit-toc.html b/maui-toolkit-toc.html index be427528..779c31ef 100644 --- a/maui-toolkit-toc.html +++ b/maui-toolkit-toc.html @@ -168,6 +168,7 @@
  • Add custom labels to the chart axis
  • Customize each chart axis label using the callback event
  • Get the data point collection based on region
  • +
  • Why tooltip and data labels not visible in release mode
  • diff --git a/maui-toolkit/Cartesian-Charts/Why-tooltip-and-data-labels-not-visible-in-release-mode.md b/maui-toolkit/Cartesian-Charts/Why-tooltip-and-data-labels-not-visible-in-release-mode.md new file mode 100644 index 00000000..f42fb175 --- /dev/null +++ b/maui-toolkit/Cartesian-Charts/Why-tooltip-and-data-labels-not-visible-in-release-mode.md @@ -0,0 +1,79 @@ +--- +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 + +In [SfCartesianChart](https://help.syncfusion.com/cr/maui-toolkit/Syncfusion.Maui.Toolkit.Charts.SfCartesianChart.html), the binding context inside tooltip and data label templates is not your business model directly. These templates run with Chart specific contexts. + +* Tooltip template: chart:[TooltipInfo](https://help.syncfusion.com/cr/maui-toolkit/Syncfusion.Maui.Toolkit.Charts.TooltipInfo.html) +* Data label template: chart:[ChartDataLabel](https://help.syncfusion.com/cr/maui-toolkit/Syncfusion.Maui.Toolkit.Charts.ChartDataLabel.html) + +Both provide an `Item` property that references the actual data object from the series [ItemsSource](https://help.syncfusion.com/cr/maui-toolkit/Syncfusion.Maui.Toolkit.Charts.ChartSeries.html#Syncfusion_Maui_Toolkit_Charts_ChartSeries_ItemsSourceProperty). Bind your fields through Item to display values from your business model. + +Release builds can remove types that are referenced only from XAML. To prevent this, reference a value converter from XAML and preserve your ViewModel, business model, and converter classes. With .NET 9 compiled bindings, set **x:DataType="chart:TooltipInfo"** for tooltip templates and **x:DataType="chart:ChartDataLabel"** for data label templates, then bind via Item. Use the converter to extract the required property from Item. + + +{% highlight xaml %} + + + + + + + + + + + + + + + + + + + + + +{% 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 %} + +## 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) \ No newline at end of file