Show Label/Text for marked zone in Silverlight RadChart

3 posts, 1 answers
  1. D4
    D4 avatar
    3 posts
    Member since:
    May 2010

    Posted 29 Nov 2010 Link to this post

    Hi,
      We are making use of telerik silverlight chart and want to show the label for marked zone as in the asp.net radChart here http://www.telerik.com/help/aspnet-ajax/understandingelementsplotareamarkedzones.html.
    There is no property with the name Label for marked zone.
     Is there anyway that we can achieve this?

    Thanks
    Dev
  2. Answer
    Evgeni "Zammy" Petrov
    Admin
    Evgeni "Zammy" Petrov avatar
    168 posts

    Posted 01 Dec 2010 Link to this post

    Hello Donlad,

     This is not a supported feature, however, it is easy to achieve this by retemplating the MarkedZone.
    In XAML you will need to retemplate MarkedZone class:

    <Style x:Key="NewMarkedZones" TargetType="telerik:MarkedZone">
        <Setter Property="Background" Value="#66666666" />
        <Setter Property="Template" >
            <Setter.Value>
                <ControlTemplate TargetType="telerik:MarkedZone">
                    <Grid>
                        <Rectangle Grid.ColumnSpan="3"
                            Fill="{TemplateBinding Background}"
                           Stroke="{TemplateBinding Stroke}"
                           StrokeThickness="{TemplateBinding StrokeThickness}"
                           Margin="{TemplateBinding ElementMargin}"
                           Style="{TemplateBinding ElementStyle}" />
                        <TextBlock  Text="{Binding}" Margin="{TemplateBinding ElementMargin}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    I have marked the new part of the MarkedZone style in orange.
    I added a grid layout wrapper and put a TextBlock together with the rectangle that actually displays the marked zone.

    In code behind you need to add MarkedZone's new style together with a string for a DataContext. This string is bound to Text  property of TextBlock:

    RC1.DefaultView.ChartArea.Annotations.Add(
               new MarkedZone(25, 50, 50000, 65000)
               {
                   Style = this.LayoutRoot.Resources["NewMarkedZones"] as Style,
                   DataContext = "Label text"
               }
           );

    I hope this will help you out.

    Kind regards,
    Evgeni "Zammy" Petrov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. D4
    D4 avatar
    3 posts
    Member since:
    May 2010

    Posted 01 Dec 2010 Link to this post

    Thank you so much Evgeni.
    Its working great.

    Regards
    Dev
Back to Top