Pre loader

Relative Annotation Location

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

I need to put a text box annotation that is located in the top left of the chart. It should remain at the top left even when the chart is zoomed, moved, etc. This should likely be some sort of anchor?

Version
5.2.1.11718
  • You must to post comments
1
0

I figured it out. Use a custom TextAnnotation and then set the Horizontal and Vertical Alignment properties.

    <Style x:Key="TextAnnotationTopLeft" TargetType="s:TextAnnotation">

        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Top" />


        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="s:TextAnnotation">
                    <Border x:Name="PART_TextAnnotationRoot"
                        Margin="{TemplateBinding Margin}"
                        Background="White"
                        BorderBrush="Purple"
                        BorderThickness="0"
                        CornerRadius="{TemplateBinding CornerRadius}">
                        <TextBox x:Name="PART_InputTextArea"
                                 Margin="10"
                                 VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                 AcceptsReturn="True"
                                 Background="White"                                    
                                 FontFamily="{TemplateBinding FontFamily}"
                                 FontSize="{TemplateBinding FontSize}"
                                 FontWeight="Bold"
                                 Foreground="Black"                                     
                                 IsTabStop="{TemplateBinding IsEditable}"
                                 Text="{Binding Text,
                                            RelativeSource={RelativeSource TemplatedParent},
                                            Mode=TwoWay}"
                                 TextAlignment="{TemplateBinding TextAlignment}"
                                 TextWrapping="Wrap" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
  • You must to post comments
0
0

Hey Chris,

I’m glad you figured it out, however this is also a feature native to SciChart.

See usage of Annotation.CoordinateMode = CoordinateMode.Relative.

In this mode, the X1,Y1 coordinates are from 0.0 to 1.0 where 0.0 is the left (or bottom) edge of the chart, and 1.0 is the right (or top) edge of the chart.

Furthermore, TextAnnotation can be anchored to the left / top (controlling where the X,Y coordinate operates from) using the HorizontalAnchorPoint and VerticalAnchorPoint properties.

Best regards,
Andrew

  • Chris Kirkman
    Thanks Andrew. This might actually work better for me since I’ve yet to be able to get a text box to pin up to the top right. I have had success on the top left, just not the top right. I’ll give that a try.
  • Andrew Burnett-Thompson
    So use CoordinateMode.Realtive. Set x1,y1 to 0.98 and set HorizontalAnchorPoint = right and VerticalAnchorPoint=top. It’ll work!
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies