Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SuryaKaran2143/How-to-show-the-Others-category-values-in-WinUI-Pie-Chart-data-label
This sample demonstrates how to bind the pie chart data label to “Others” category values in WinUI (SfCircularChart).
https://github.com/SuryaKaran2143/How-to-show-the-Others-category-values-in-WinUI-Pie-Chart-data-label
chart data-label pie-chart winui
Last synced: 2 months ago
JSON representation
This sample demonstrates how to bind the pie chart data label to “Others” category values in WinUI (SfCircularChart).
- Host: GitHub
- URL: https://github.com/SuryaKaran2143/How-to-show-the-Others-category-values-in-WinUI-Pie-Chart-data-label
- Owner: SuryaKaran2143
- Fork: true (SyncfusionExamples/How-to-show-the-Others-category-values-in-WinUI-Pie-Chart-data-label)
- Created: 2023-08-21T04:28:29.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-08-21T04:30:14.000Z (over 1 year ago)
- Last Synced: 2023-08-21T05:29:24.105Z (over 1 year ago)
- Topics: chart, data-label, pie-chart, winui
- Language: C#
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# How to show the "Others” category values in WinUI Pie Chart data label
This sample demonstrates how to show the pie chart data label to “Others” category values in WinUI (SfCircularChart).
The ContentTemplate property can be used to customize the data label of the pie chart by using the Context property with an IValueConverter. To show the data label in the "Others" category, we can use the GroupTo and GroupMode properties in the CircularSeries. The following code example demonstrates how to bind the data label of the pie chart to the "Others" category in the SfCircularChart.**[XAML]**
```…
```
**[C#]**
```
public class DataLabelXValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
ChartDataLabel pieAdornment = value as ChartDataLabel;
if(pieAdornment.Item is List)
{
return "Others";
}
else if ((pieAdornment.Item as Model).Product != null)
{return string.Format((pieAdornment.Item as Model).Product.ToString());
}
else
return null;
}public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}public class DataLabelYValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
ChartDataLabel pieAdornment = value as ChartDataLabel;
if (pieAdornment.Item is List)
{
var data = pieAdornment.Item as List;
var yValue = data.Sum(item => (item as Model).SalesPercentage);
return yValue.ToString("P0");
}
else if (!double.IsNaN((pieAdornment.Item as Model).SalesPercentage))
{return (pieAdornment.Item as Model).SalesPercentage.ToString("P0");
}
else
return null;
}public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}```
**Output**
**See also**
* [Data template in WinUI Circular chart](https://help.syncfusion.com/winui/circular-charts/datalabels#template).