This is a migrated thread and some comments may be shown as answers.

Is it possible to annotate CustomGridLines?

1 Answer 87 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Alexis
Top achievements
Rank 1
Alexis asked on 01 Dec 2010, 05:19 PM
I have been trying to use the CustomGridLines feature to highlight a particular date, what I'd like to do is add a label next to the line, explaining what it's highlighting. Is this possible at all?
Thanks

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 06 Dec 2010, 01:51 PM
Hello Alexis,

It is possible to add Label for your Custom Gridline by retemplating the CustomGridLine. Put this code snippet between UserControl.Resources opening and closing tags:
<SolidColorBrush x:Key="AxisStroke" Color="#FF000000" />
          
        <Style x:Key="CustomGridLineStyle"
            TargetType="telerikCharting:CustomGridLine" >
            <Setter Property="Stroke" Value="{StaticResource AxisStroke}" />
            <Setter Property="StrokeThickness" Value="1" />
            <Setter Property="Template" >
                <Setter.Value>
                    <ControlTemplate TargetType="telerikCharting:CustomGridLine">
                        <Grid>
                        <Line X1="{TemplateBinding ElementX1}" 
                          X2="{TemplateBinding ElementX2}" 
                          Y1="{TemplateBinding ElementY1}" 
                          Y2="{TemplateBinding ElementY2}" 
                          Stroke="{TemplateBinding Stroke}"
                          StrokeThickness="{TemplateBinding StrokeThickness}"
                          Style="{TemplateBinding ElementStyle}"/>
                          <TextBlock Text="{Binding}"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
A grid layout wrapper is addded containing a TextBlock together with the Line that actually displays the custom gridline ( I've marked the new things added to the default template with yellow).

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

RadChart1.DefaultView.ChartArea.Annotations.Add(
              new CustomGridLine()
              {
                  Margin = new Thickness(5,90,0,0),
                  YIntercept = 90,
                  Stroke = new SolidColorBrush(Colors.Purple),
                  StrokeThickness = 2,
                  Style = this.Resources["CustomGridLineStyle"] as Style,
                  DataContext = "My custom text",
              });

Have in mind that with this approach you will be able to locate the Label of the CustomGridLine by applying Margin to it as shown above.

Kind regards,
Evgenia
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Chart
Asked by
Alexis
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or