Hi,
I’m using the following code to create a text annotation:
private void AddLabel(DateTime StartTime, DateTime EndTime, string label)
{
TextAnnotation text = new TextAnnotation();
text.YAxisId = "LeftAxis";
text.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
text.Text = label;
text.CoordinateMode = AnnotationCoordinateMode.RelativeY;
text.X1 = StartTime;
text.X2 = EndTime;
text.Y1 = .05;
text.Y2 = 0;
text.TextAlignment = TextAlignment.Center;
text.TextStretch = Stretch.UniformToFill;
text.Background = new SolidColorBrush(Color.FromArgb(0x80, 0x80, 0x80, 0x80));
text.BorderBrush = new SolidColorBrush(Color.FromArgb(0xC0, 0xD0, 0xD0, 0xD0));
text.BorderThickness = new Thickness(2);
sciChart.Annotations.Add(text);
}
Unfortunately the text doesn’t scale like I want it to though. The size of the text stays the same even when the chart is small, making the height greater than .05. Is there a way to make the text get smaller as the chart is shrunk so that it stays within the .05 Y boundary?
I attached 2 images to illustrate the issue.
Thanks,
Greg
- Sean Clifford asked 11 years ago
- last edited 10 years ago
- You must login to post comments
Hi Greg,
Hm…in this case I can suggest you changing the FontSize of annotations dynamically or modifying a Template of TextAnnotaion. Please, try using following control template:
<ControlTemplate TargetType="s:TextAnnotation"> <Border x:Name="PART_TextAnnotationRoot" Margin="{TemplateBinding Margin}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}"> <Viewbox Stretch="{TemplateBinding TextStretch}"> <TextBox x:Name="PART_InputTextArea" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalAlignment}" AcceptsReturn="True" Background="Transparent" BorderThickness="0" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontWeight="{TemplateBinding FontWeight}" Foreground="{TemplateBinding Foreground}" IsEnabled="{Binding CanEditText, RelativeSource={RelativeSource TemplatedParent}}" IsTabStop="{TemplateBinding IsEditable}" Style="{StaticResource AnnotationTextBoxStyle}" Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="Wrap" /> </Viewbox> </Border> </ControlTemplate>
Also you can find info about how to apply a template to a control in code in How to generate RolloverMarkerTemplate in code topic.
Please, let us know if this helps,
Best regards,
Yuriy
- Yuriy Zadereckiy answered 11 years ago
-
Thanks, that does help. If you don't mind I have another real quick question related to this issue. Is there any way that I can make it where a text annotation is always above the box annotations? Right now it seems to give a greater Z-Index to whatever annotation was last rendered onto the chart as the chart is panned, so I end up with some box annotations in front of the text annotation and some behind. Thanks for your help, I appreciate it. Greg
-
This is an old comment but for sake of keeping the forums current - you can change ZIndex of annotations using the Panel.ZIndex property (or change their order in the AnnotationCollection). I would also suggest investigating TextAnnotation.LayoutTransform (ScaleTransform) and adjusting the scale factors to achieve the same affect.
- You must login to post comments
Another solution to make the TextAnnotation size small when the chart is resized is presented here:
Text Annotation Resizing with FontSize Binding
This is a very simple solution requiring just one binding per annotation plus a converter.
Hope this helps!
Best regards,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
- You must login to post comments
Please login first to submit.