Displaying Data Labels as Percentage

Dec 19, 2014 at 6:49 AM
Edited Dec 19, 2014 at 8:54 AM
Please tell me how to show Data labels as percentage in pie chart and all other charts?
Jan 1, 2015 at 10:50 AM
Is anyone entertaining this thread?

I'm also looking for the solution.
Jan 7, 2015 at 11:09 PM
Yes it is possible, I did something similar for my own needs. You have to spot the name of the control containing the label and override the default style. Unfortunately it depends of the chart type and I do not have a generic solution for all kind of charts.

To continue our example, for the pie charts, you will have to override the default style for the pie piece. You will note that I have added the StringFormat where I needed..
<Style TargetType="chart:PiePiece">
                        <Setter Property="Background" Value="Transparent" />
                        <Setter Property="BorderBrush" Value="White" />
                        <Setter Property="BorderThickness" Value="0" />
                        <Setter Property="IsTabStop" Value="False" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="chart:PiePiece">
                                    <Canvas x:Name="Root">
                                        <Path x:Name="Slice" Data="{TemplateBinding Geometry}" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeMiterLimit="1">
                                            <ToolTipService.ToolTip>
                                                <StackPanel>
                                                    <ContentControl Content="{TemplateBinding Value, Converter={StaticResource MoneyC}}" />
                                                </StackPanel>
                                            </ToolTipService.ToolTip>
                                        </Path>
                                        <Path x:Name="LabelLine" Data="{TemplateBinding LineGeometry}" StrokeThickness="1" StrokeMiterLimit="1" Stroke="{TemplateBinding Foreground}"  IsHitTestVisible="False" />
                                        <TextBlock x:Name="PART_Label"  Margin="2" >
                                            <TextBlock.Text>
                                                <Binding Path="Value"   StringFormat="{}{0}%" RelativeSource="{RelativeSource Mode=TemplatedParent}"/>
                                            </TextBlock.Text>
                                        </TextBlock>
                                    </Canvas>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
Jan 8, 2015 at 6:45 AM
Thanks patra for your support. The code snippet helped.
Jul 30, 2015 at 6:16 PM
Thanks a lot.

For BarCharts I did the following:
<Style TargetType="chart:AutoSizeTextBlock">
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="chart:AutoSizeTextBlock">
                    <Border x:Name="PART_Border" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0">
                        <TextBlock x:Name="PART_TextBlock" VerticalAlignment="Center" Margin="5 0 5 0"  Opacity="1" HorizontalAlignment="Center" Style="{TemplateBinding TextBlockStyle}" >
                                            <TextBlock.Text>
                                                <Binding Path="Value"   StringFormat="{}{0}%"/>
                                            </TextBlock.Text>
                        </TextBlock>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>