How to display label in Pieseries for Phone

3 posts, 0 answers
  1. enamul
    enamul avatar
    1 posts
    Member since:
    Apr 2012

    Posted 28 Apr 2012 Link to this post

    I am newbie to Telerik controls. Trying to create a pie chart with lables, but not able to find a complete example in Telerik help files.

    xaml
    <chart:RadPieChart x:Name="gPie" Margin="27,95,143,276" Grid.Row="1" DataContext="{Binding}">
                <chart:PieSeries ShowLabels="True" DataContext="{Binding}">
                    <chart:PieSeries.SliceStyles>
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="Magenta"/>
                        </Style>
     
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="LimeGreen"/>
                        </Style>
     
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="DarkOrange"/>
                        </Style>
     
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="Purple"/>
                        </Style>
     
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="Green"/>
                        </Style>
     
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="Red"/>
                        </Style>
                        <Style TargetType="Path">
                            <Setter Property="Fill" Value="Blue"/>
                        </Style>
                    </chart:PieSeries.SliceStyles>
                     
                    <!--<chart:PieSeries.LabelTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}"
                                   FontSize="14"
                                   Foreground="{StaticResource PhoneBackgroundBrush}"
                                   FontWeight="Bold"/>
                        </DataTemplate>
                    </chart:PieSeries.LabelTemplate>-->
                </chart:PieSeries>
            </chart:RadPieChart>

    And I am setting the value in C#:
    this.gPie.Series[0].ItemsSource = new double[] { iFajr, iDohr, iAsr, iMagrib, iEsha, iFasting, iHajj };

    The pie chart displays fine with %-tile lable for each item. But I like to use custom lable for them. How do I do it? Also, Is there a way to display the lables on the side (with a color icon and corresponding text), not on the chart itself?
  2. RoboticPet
    RoboticPet avatar
    2 posts
    Member since:
    Apr 2012

    Posted 30 Apr 2012 Link to this post

    enamul, it looks like you can do part of what you want by using Standard Numeric Format Strings (http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx).  E.g. if you set LabelFormat on the PieSeries to "n2" you will get the percentages in decimals of two digits with no percent sign.

    However, what I want to do is just show the actual values that I specified as the PieDataPoints (whole numbers).  What is the recommended way to do that?
  3. DevCraft banner
  4. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 02 May 2012 Link to this post

    Hello Enamul,

    Thanks for the question

    If I understood you correctly you are asking whether the chart can display a legend? If this is indeed your requirement you will have to create the legend manually, since RadChart does not yet support automatic legend generation. Currently, all customization of the labels should be done within the LabelTemplate in the pie series. For special formatting you can use a binding converter that converts the actual label string to anything you deem appropriate for your scenario.

    Please write again if you have other questions.

    Greetings,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top