Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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).

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**

Output

**See also**

* [Data template in WinUI Circular chart](https://help.syncfusion.com/winui/circular-charts/datalabels#template).