SciChart WPF 2D Charts > Annotations API > The LineAnnotation Type
The LineAnnotation Type

The LineAnnotation type draws a line from X1Y1 to X2Y2, where coordinates are data-values.

 

 

 

Declaring a LineAnnotation in XAML

Declaring a LineAnnotation
Copy Code
<!-- Where xmlns:s="http://schemas.abtsoftware.co.uk/scichart" -->
<s:SciChartSurface>
   <s:SciChartSurface.Annotations>
      <!-- Declares a LineAnnotation at X1=1, X2=2, Y1=4, Y2=6 -->
         <!-- The annotation will move with the chart as you zoom and pan -->
      <s:LineAnnotation Stroke="#555" StrokeThickness="2" X1="1" X2="2" Y1="4" Y2="6"
                        IsEditable="True"/>
   </s:SciChartSurface.Annotations>
</s:SciChartSurface>

Declaring a LineAnnotation in Code

Declaring a LineAnnotation
Copy Code
var sciChartSurface = new SciChartSurface();
sciChartSurface.Annotations.Add(new LineAnnotation()
{
   Stroke = new SolidColorBrush(Colors.FromArgb(0xFF, 0x55, 0x55, 0x55)),
   StrokeThickness = 2,
   X1 = 1,
   X2 = 2,
   Y1 = 4,
   Y2 = 6,
   IsEditable = true,
});

Templating the LineAnnotation

The Default Style and ControlTemplate for the LineAnnotation is defined below. You shouldn’t need to change this, but if you want to template the annotation, here are the template parts:

Templating the LineAnnotation
Copy Code
<Style BasedOn="{StaticResource AnnotationBaseStyle}" TargetType="a:LineAnnotation">
   <Setter Property="Stroke" Value="{me:ThemeBinding RubberBandStrokeBrush}" />
   <Setter Property="StrokeThickness" Value="2.0" />
   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="a:LineAnnotation">
            <Grid x:Name="PART_LineAnnotationRoot">
               <Line x:Name="PART_GhostLine"
                    Stroke="Transparent"
                    StrokeThickness="{s:Static Member=visuals:ManipulationMargins.AnnotationLineWidth}" />
               <Line x:Name="PART_Line"
                    Stroke="{TemplateBinding Stroke}"
                    StrokeDashArray="{TemplateBinding StrokeDashArray}"
                    StrokeThickness="{TemplateBinding StrokeThickness}" />
            </Grid>
         </ControlTemplate>
      </Setter.Value>
   </Setter>
</Style>
Where AnnotationBaseStyle is defined as
<!--  Annotations  -->
<Style x:Key="AnnotationBaseStyle" TargetType="a:AnnotationBase">
   <Style.Setters>
      <Setter Property="IsTabStop" Value="False" />
      <Setter Property="Foreground" Value="{me:ThemeBinding TickTextBrush}" />
      <Setter Property="FontSize" Value="12" />
   </Style.Setters>
</Style>