annotation text

5 posts, 0 answers
  1. Yonghan
    Yonghan avatar
    27 posts
    Member since:
    Dec 2010

    Posted 05 Jan 2011 Link to this post

    Hi,

    Is there any way to implement annotation text in line or stepline chart?
    I want to show some annotation text over ChartArea.
    How can I achive that?

    I have attached the image of desired chart.

    Thanks
  2. Yonghan
    Yonghan avatar
    27 posts
    Member since:
    Dec 2010

    Posted 05 Jan 2011 Link to this post

    Hi,
    I made TextAnnotation based on AnnotationBase,
    But some objects are interals, so I can't calculate X,Y position.

    I realy need this.
    Somebody help me.


      <Style TargetType="local:TextAnnotation">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="local:TextAnnotation">
              <Canvas x:Name="PART_RootElement" Background="Transparent">
                <Border Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}"
                        Canvas.Left="{TemplateBinding ActualX}" Canvas.Top="{TemplateBinding ActualY}">
                  <ContentControl VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalAlignment}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                FontFamily="{TemplateBinding FontFamily}"
                                >
                    <ContentControl.Content>
                      <TextBlock Text="{TemplateBinding Text}" TextTrimming="WordEllipsis" Margin="2"
                               Foreground="{TemplateBinding Foreground}"
                               ToolTipService.ToolTip="{TemplateBinding Text}"/>
                    </ContentControl.Content>
                  </ContentControl>
                </Border>
              </Canvas>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>

      public class TextAnnotation : AnnotationBase
      {

        public TextAnnotation()
        {
          this.DefaultStyleKey = typeof(TextAnnotation);
        }

        protected override void Update()
        {
           // base.ChartArea is interal!!!
        }

        public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(TextAnnotation), new PropertyMetadata("note"));
        public string Text
        {
          get { return (string)base.GetValue(TextProperty); }
          set { base.SetValue(TextProperty, value); }
        }

        public static readonly DependencyProperty XProperty = DependencyProperty.Register("X", typeof(double), typeof(TextAnnotation), new PropertyMetadata(0d, X_OnChanged));
        public double X
        {
          get { return (double)base.GetValue(XProperty); }
          set { base.SetValue(XProperty, value); }
        }

        public static readonly DependencyProperty YProperty = DependencyProperty.Register("Y", typeof(double), typeof(TextAnnotation), new PropertyMetadata(0d, Y_OnChanged));
        public double Y
        {
          get { return (double)base.GetValue(YProperty); }
          set { base.SetValue(YProperty, value); }
        }

        public static void X_OnChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
          ((TextAnnotation) o).ActualX = (double) e.NewValue;
          // convert data to cavas.Y ???
        }

        public static void Y_OnChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
          ((TextAnnotation)o).ActualY = (double)e.NewValue;
          // convert data to canvas.Y ???
        }

        public static readonly DependencyProperty ActualXProperty = DependencyProperty.Register("ActualX", typeof(double), typeof(TextAnnotation), new PropertyMetadata(0d));
        public double ActualX
        {
          get { return (double)base.GetValue(ActualXProperty); }
          internal set { base.SetValue(ActualXProperty, value); }
        }

        public static readonly DependencyProperty ActualYProperty = DependencyProperty.Register("ActualY", typeof(double), typeof(TextAnnotation), new PropertyMetadata(0d));
        public double ActualY
        {
          get { return (double)base.GetValue(ActualYProperty); }
          internal set { base.SetValue(ActualYProperty, value); }
        }

      }
    }

  3. Evgeni "Zammy" Petrov
    Admin
    Evgeni "Zammy" Petrov avatar
    168 posts

    Posted 07 Jan 2011 Link to this post

    Hi Yonghan,

     You can show text in annotation zone by re-templating it. I have attached a project, showing this.

    Hope this helps.

    All the best,
    Evgeni "Zammy" Petrov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  4. Yonghan
    Yonghan avatar
    27 posts
    Member since:
    Dec 2010

    Posted 10 Jan 2011 Link to this post

    Thank you Zammy.
    I appreciate that.

    But I have more problems.
    _ I can't see MarkedZone under line series (ToolTipService is not working)
    _ overflowed text is clipped.

    Can I set hover effect to MarkedZone?

    Thanks.
  5. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 13 Jan 2011 Link to this post

    Hi Yonghan,

    To be able to see the Tooltips for MarkedZones you should retemplate the Chart Area and put the Annotations Layer within the Zoom Layer for example. Then by using TooltipService.ToolTip property of the MarkedZone you can set custom tooltip. You can find a sample project attached demonstrating what I mean.
    Additionally to make the text in MarkedZone wrapped (this way the overflowed text does not clips) 
    you can set the TextWrapping property of the MarkedZone's Text Block to Wrap. You can find this set in the MarkedZones Style.

    I hope this helps.

    Greetings,
    Evgenia Milcheva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top