Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
need to show Percents on XamPieChart(Infragistics 2014)
posted

Hi

I need to show percents on XamPieChart(Infragistics 2014)

I checked infragistics 2014 sample browser

and XamPieChart - Labels With Percentage - Options - Labels Displayed - Percent function could show the percentage.

But couldn't find how to use it

Could you advise me how to ?

Thanks for ur support in advance

Parents
No Data
Reply
  • 2660
    Offline posted

    Hello,

    Thank you for posting to Infragistics Community!

    Please, find attached below a sample app demonstrating how to display the item labels in the XamPieChart as percentage values.

    The approach involves defining a LabelTemplate for the chart:

     <ig:XamPieChart Name="pieChart"
    …
    LabelTemplate="{StaticResource labelTemplate1}"/>

    As you can see, the text is bound to a property of the Label DataContext named “PercentValue” and additionally, a custom converter is used to adjust the percent value:

    <Grid.Resources>
         <local:ValueToPercentConverter x:Key="conv" />
         <DataTemplate x:Key="labelTemplate1">
             <StackPanel Orientation="Vertical">
                 <TextBlock Text="{Binding PercentValue, StringFormat=P, Converter={StaticResource conv}}" />
             </StackPanel>
         </DataTemplate>
     </Grid.Resources>

       public class ValueToPercentConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
          {
              double dv = (double)value;
              if (dv > 0)
                  return dv / 100;
     
              return value;
          }
     
          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
          {
              throw new NotImplementedException();
          }
    }

    In conclusion, please, check out the sample and let me know if it helps.

    Best regards,
    Bozhidara Pachilova
    Software Developer

    XamPieChartPercentages.zip

Children
No Data