Group label change

I have a pie chart where it dynamically adds values. I have set the grouping below a certain value. And it works fine. The label "Others" appears on the chart, but as all the data is in Polish, I would like to name this label in Polish as well, but I do not find such an option anywhere. I have already searched the web and found no hint anywhere. I will be grateful for any help.


5 Replies

DD Devakumar Dhanapoosanam Syncfusion Team July 26, 2022 09:30 AM UTC

Hi Piotr,


We can achieve your requirement using the legend ItemTemplate and by using Converter to customize the label based on your requirement as per in the below code example.


<chart:SfChart x:Name="chart">

     <chart:SfChart.Resources>

         <local:PieChartLabelConverter x:Key="labelConverter"/>

         <DataTemplate x:Key="itemTemplate">

             <StackPanel Orientation="Horizontal" Margin="10,0,10,0" >

                 <Ellipse Width="{Binding IconWidth}" Height="{Binding IconHeight}"

                                Fill="{Binding Interior}" Margin="4"/>

                 <TextBlock HorizontalAlignment="Center" FontSize="12"

                            Foreground="Black" FontWeight="SemiBold"

                            Text="{Binding Label, Converter={StaticResource labelConverter}}">

                 </TextBlock>

             </StackPanel>

         </DataTemplate>

     </chart:SfChart.Resources>

   

     <chart:SfChart.Legend>

         <chart:ChartLegend DockPosition="Bottom"

                            ItemTemplate="{StaticResource itemTemplate}">

         </chart:ChartLegend>

     </chart:SfChart.Legend>

 </chart:SfChart>


public class PieChartLabelConverter : IValueConverter

{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

        if (value != null)

        {

            if (value.ToString() == "Others")

            {

                //change others grouping label as per your requirement

                return "Polish";

            }

            else

                return value;

        }

 

        return "";

    }

 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

    {

        return value;

    }

}


Please refer below link for more details.

https://help.syncfusion.com/wpf/charts/legend#customization


Also, refer the below chart demo example link for customizing the grouping data label using LabelTemplate property.

GitHub sample: https://github.com/essential-studio/wpf-demos/blob/development/chart/Views/Circular%20Charts/PieChart.xaml

https://help.syncfusion.com/wpf/charts/adornments/label#label-template


Please find the sample in the attachment below and let us know if you need any further assistance.


Regards,

Devakumar D


Attachment: SF_176421_dcd40252.zip


PI Piotr replied to Devakumar Dhanapoosanam July 26, 2022 10:00 AM UTC

Wow, thank you so much. Works perfectly! 

Please forgive me, but I will only ask you one more thing.

Now the tooltip shows me all the data ... except the grouped ones. At the moment I have such a tooltip:

 <syncfusion:PieSeries.TooltipTemplate>

                                <DataTemplate>

                                    <Border Background="Black">

                                        <StackPanel Orientation="Vertical">

                                            <StackPanel Orientation="Horizontal">

                                                <TextBlock Text="{Binding Item.ContractNumber}"

                                                           Foreground="White" />

                                                <TextBlock Text=" - "

                                                           Foreground="White" />

                                                <TextBlock Text="{Binding Item.Percentage, StringFormat=P}"

                                                           Foreground="White"

                                                           HorizontalAlignment="Right" />

                                            </StackPanel>

                                        </StackPanel>

                                    </Border>

                                </DataTemplate>

                            </syncfusion:PieSeries.TooltipTemplate>


 What should I add there so that it displays to me in one group what has been grouped?

Once again, thank you very much for your help so far and sorry to be so tiring.



DD Devakumar Dhanapoosanam Syncfusion Team July 27, 2022 06:53 AM UTC

Hi Piotr,


Query: What should I add there so that it displays to me in one group what has been grouped?


We can achieve your requirement using the series TooltipTemplate and by using Converter to customize the tooltip based on your requirement. The DataContext for each template will be the respective pie segment and by using this we can customize tooltip as per in the below code example.


<chart:PieSeries.TooltipTemplate>

    <DataTemplate>

        <Border Background="Black">

            <StackPanel Orientation="Vertical">

                <StackPanel Orientation="Horizontal">

                    <TextBlock Text="{Binding Converter={StaticResource tooltipConverter},

                                                                     ConverterParameter='Label'}"

                                           Foreground="White" />

                    <TextBlock Text=" - " Foreground="White" />

                    <TextBlock Text="{Binding Converter={StaticResource tooltipConverter}}"

                                           Foreground="White" HorizontalAlignment="Right" />

                </StackPanel>

            </StackPanel>

        </Border>

    </DataTemplate>

</chart:PieSeries.TooltipTemplate>


public class TooltipLabelConverter : IValueConverter

{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

        if (value != null)

        {

            var pieSegment = value as PieSegment;

            var item = pieSegment.Item as List<object>;

            if (parameter != null && parameter.ToString() == "Label")

            {

                return item is List<object> ? "Polish" : (pieSegment.Item as PieChartModel).Country;

            }

            else

            {

                return item is List<object> ? item.Sum(x => (x as PieChartModel).Count).ToString("P")

                    : (pieSegment.Item as PieChartModel).Count.ToString("P");

            }

        }

 

        return "";

    }

 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

    {

        return value;

    }

}


Chart, pie chart

Description automatically generated


Please refer below link for more details.

https://help.syncfusion.com/wpf/charts/interactive-features/tooltip#customizing-the-appearance


Please find the sample in the attachment below and let us know if you need any further assistance.


Regards,

Devakumar D


Attachment: SF_176421_1188c7a3.zip


PI Piotr September 1, 2022 07:41 PM UTC

Thank you very much!



DD Devakumar Dhanapoosanam Syncfusion Team September 2, 2022 05:05 AM UTC

Hi Piotr,


Thanks for your update.


Please let us know if you need any further assistance.


Regards,

Devakumar D


Loader.
Up arrow icon