-
Notifications
You must be signed in to change notification settings - Fork 5
MAUI-988662 - [Others] Updated UG for how to display tooltip and datalabels in release mode #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AswiniDileep
wants to merge
5
commits into
development
Choose a base branch
from
MAUI-988662-Added-howto-UG-for-KB
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
421e1b1
MAUI-988662-[Others]: Updated UG for KB
AswiniDileep 63d975f
MAUI-988662-[Others]: Update title
AswiniDileep 076ab7f
MAUI-988662-[Others]: Updated title
AswiniDileep 1ab632f
MAUI-988662-[Others]: Updated content
AswiniDileep eb20108
MAUI-988662-[Others]: Updated title to clear warning
AswiniDileep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
maui-toolkit/Cartesian-Charts/Display-tooltip-datalabels-in-release-mode.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As using same converter for both tooltip and datalabel rename the TooltipConverter with any common name.