menu

MAUI Toolkit

  • User Guide
  • Demos
  • Support
Class ShapeAnnotation - MAUI-ToolKit API Reference | Syncfusion

    Show / Hide Table of Contents

    Class ShapeAnnotation

    ShapeAnnotation allows you to add annotations in the form of shapes such as rectangles, ellipses, lines, horizontal lines, and vertical lines at specific areas of interest within the chart area.

    Inheritance
    System.Object
    ChartAnnotation
    ShapeAnnotation
    EllipseAnnotation
    LineAnnotation
    RectangleAnnotation
    Inherited Members
    ChartAnnotation.CoordinateUnit
    ChartAnnotation.CoordinateUnitProperty
    ChartAnnotation.IsVisible
    ChartAnnotation.IsVisibleProperty
    ChartAnnotation.X1
    ChartAnnotation.X1Property
    ChartAnnotation.XAxisName
    ChartAnnotation.XAxisNameProperty
    ChartAnnotation.Y1
    ChartAnnotation.Y1Property
    ChartAnnotation.YAxisName
    ChartAnnotation.YAxisNameProperty
    Namespace: Syncfusion.Maui.Toolkit.Charts
    Assembly: Syncfusion.Maui.Toolkit.dll
    Syntax
    public abstract class ShapeAnnotation : ChartAnnotation, IThemeElement

    Constructors

    ShapeAnnotation()

    Initializes a new instance of the ShapeAnnotation class.

    Declaration
    public ShapeAnnotation()

    Fields

    FillProperty

    Identifies the Fill bindable property.

    Declaration
    public static readonly BindableProperty FillProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The Fill property sets the fill color of the ShapeAnnotation.

    LabelStyleProperty

    Identifies the LabelStyle bindable property.

    Declaration
    public static readonly BindableProperty LabelStyleProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The LabelStyle property allows customization of the appearance of the label associated with the ShapeAnnotation.

    StrokeDashArrayProperty

    Identifies the StrokeDashArray bindable property.

    Declaration
    public static readonly BindableProperty StrokeDashArrayProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The StrokeDashArray property defines the dash pattern used for the border or outline of the ShapeAnnotation.

    StrokeProperty

    Identifies the Stroke bindable property.

    Declaration
    public static readonly BindableProperty StrokeProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The Stroke property defines the brush for the border or outline of the ShapeAnnotation.

    StrokeWidthProperty

    Identifies the StrokeWidth bindable property.

    Declaration
    public static readonly BindableProperty StrokeWidthProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The StrokeWidth property sets the thickness of the border or outline of the ShapeAnnotation.

    TextProperty

    Identifies the Text bindable property.

    Declaration
    public static readonly BindableProperty TextProperty
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The Text property defines the text content displayed within the ShapeAnnotation.

    X2Property

    Identifies the X2 bindable property.

    Declaration
    public static readonly BindableProperty X2Property
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The X2 property sets the second X-coordinate for the ShapeAnnotation in the chart.

    Y2Property

    Identifies the Y2 bindable property.

    Declaration
    public static readonly BindableProperty Y2Property
    Field Value
    Type
    Microsoft.Maui.Controls.BindableProperty
    Remarks

    The Y2 property sets the second Y-coordinate for the ShapeAnnotation in the chart.

    Properties

    Fill

    Gets or sets the fill color of the shape annotation.

    Declaration
    public Brush Fill { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Controls.Brush

    This property takes the Microsoft.Maui.Controls.Brush as its value.

    Examples
    • Xaml
    • C#
        <chart:SfCartesianChart>
    
        <!-- ... Eliminated for simplicity-->
        <chart:SfCartesianChart.Annotations>
             <chart:RectangleAnnotation X1="1" Y1="10" X2="4" Y2="20" Fill="Green"/>
        </chart:SfCartesianChart.Annotations>  
    
        </chart:SfCartesianChart>
        SfCartesianChart chart = new SfCartesianChart();     
    
        // Eliminated for simplicity
        var rectangle = new RectangleAnnotation()
        {
            X1 = 1,
            Y1 = 10,
            X2 = 4,
            Y2 = 20,
            Fill = Colors.Green,
        };
    
        chart.Annotations.Add(rectangle);

    LabelStyle

    Gets or sets the value to customize the appearance of shape annotation text.

    Declaration
    public ChartAnnotationLabelStyle LabelStyle { get; set; }
    Property Value
    Type Description
    ChartAnnotationLabelStyle

    This property takes the ChartAnnotationLabelStyle as its value.

    Examples
    • Xaml
    • C#
        <chart:SfCartesianChart>
    
        <!-- ... Eliminated for simplicity-->
        <chart:SfCartesianChart.Annotations>
             <chart:HorizontalLineAnnotation X1="1" Y1="10" X2="4" Y2="20">
              <chart:HorizontalLineAnnotation.LabelStyle>
                <chart:ChartAnnotationLabelStyle  HorizontalTextAlignment="Start" VerticalTextAlignment="Start"/>
              </chart:HorizontalLineAnnotation.LabelStyle>
             </chart:HorizontalLineAnnotation>
        </chart:SfCartesianChart.Annotations>  
    
        </chart:SfCartesianChart>
        SfCartesianChart chart = new SfCartesianChart();     
    
        // Eliminated for simplicity
        var horizontalAnnotation = new HorizontalLineAnnotation()
        {
            X1 = 1,
            Y1 = 10,
            X2 = 4,
            Y2 = 20,
        };
    
       horizontalAnnotation.LabelStyle = new ChartAnnotationLabelStyle()
       {
          HorizontalTextAlignment = ChartLabelAlignment.Start,
          VerticalTextAlignment = ChartLabelAlignment.Start,
       };
    
      chart.Annotations.Add(horizontalAnnotation);

    Stroke

    Gets or sets the stroke for the annotation.

    Declaration
    public Brush Stroke { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Controls.Brush

    This property takes the Microsoft.Maui.Controls.Brush as its value.

    Examples
    • Xaml
    • C#
        <chart:SfCartesianChart>
    
        <!-- ... Eliminated for simplicity-->
        <chart:SfCartesianChart.Annotations>
             <chart:VerticalLineAnnotation X1="1" Y1="10" Stroke="Red"/>
        </chart:SfCartesianChart.Annotations>  
    
        </chart:SfCartesianChart>
        SfCartesianChart chart = new SfCartesianChart();     
    
        // Eliminated for simplicity
        var vertical = new VerticalLineAnnotation()
        {
            X1 = 1,
            Y1 = 10,
            Stroke = Colors.Red,
        };
    
        chart.Annotations.Add(vertical);

    StrokeDashArray

    Gets or sets a value to customize the appearance of the annotation border.

    Declaration
    public DoubleCollection StrokeDashArray { get; set; }
    Property Value
    Type Description
    Microsoft.Maui.Controls.DoubleCollection

    This property takes the Microsoft.Maui.Controls.DoubleCollection as its value and its default value is null

    Examples
    • Xaml
    • C#
        <chart:SfCartesianChart>
    
        <!-- ... Eliminated for simplicity-->
        <chart:SfCartesianChart.Annotations>
             <chart:VerticalLineAnnotation X1="1" Y1="10" StrokeDashArray="5,3"/>
        </chart:SfCartesianChart.Annotations>  
    
        </chart:SfCartesianChart>
        SfCartesianChart chart = new SfCartesianChart();     
    
        // Eliminated for simplicity
        var vertical = new VerticalLineAnnotation()
        {
            X1 = 1,
            Y1 = 10,
            StrokeDashArray = new [] {5,3},
        };
    
        chart.Annotations.Add(vertical);

    StrokeWidth

    Gets or sets a value that indicates the width of the annotations stroke.

    Declaration
    public double StrokeWidth { get; set; }
    Property Value
    Type Description
    System.Double

    This property takes the double as its value and its default value is 1

    Remarks

    The value needs to be greater than zero.

    Examples
    • Xaml
    • C#
        <chart:SfCartesianChart>
    
        <!-- ... Eliminated for simplicity-->
        <chart:SfCartesianChart.Annotations>
             <chart:VerticalLineAnnotation X1="1" Y1="10" StrokeWidth="5"/>
        </chart:SfCartesianChart.Annotations>  
    
        </chart:SfCartesianChart>
        SfCartesianChart chart = new SfCartesianChart();     
    
        // Eliminated for simplicity
        var vertical = new VerticalLineAnnotation()
        {
            X1 = 1,
            Y1 = 10,
            StrokeWidth = 5,
        };
    
        chart.Annotations.Add(vertical);

    Text

    Gets or sets the string value that represents the text to be displayed on the annotation.

    Declaration
    public string Text { get; set; }
    Property Value
    Type Description
    System.String

    This property takes the string as its value and its default value is string.Empty.

    Examples
    • Xaml
    • C#
        <chart:SfCartesianChart>
    
        <!-- ... Eliminated for simplicity-->
        <chart:SfCartesianChart.Annotations>
             <chart:HorizontalLineAnnotation Y1="10" Text="Text"/>
        </chart:SfCartesianChart.Annotations>  
    
        </chart:SfCartesianChart>
        SfCartesianChart chart = new SfCartesianChart();     
    
        // Eliminated for simplicity
        var horizontalAnnotation = new HorizontalLineAnnotation()
        {
            Y1 = 10,
            Text = "Text",
        };
    
        chart.Annotations.Add(horizontalAnnotation);

    X2

    Gets or sets the DateTime or double value that represents the x2 position of the annotation.

    Declaration
    public object X2 { get; set; }
    Property Value
    Type Description
    System.Object

    This property takes the object as its value and its default value is null.

    Examples
    • Xaml
    • C#
    <chart:SfCartesianChart.Annotations>
      <chart:RectangleAnnotation X1="3" Y1="20" X2="4" Y2="40">
      </chart:RectangleAnnotation>
    </chart:SfCartesianChart.Annotations>  
     SfCartesianChart chart = new SfCartesianChart();
     var rectangle = new RectangleAnnotation()
     {
       X1 = 3,
       Y1 = 20,
       X2 = 4,
       Y2 = 40,
     };
    
    chart.Annotations.Add(rectangle);

    Y2

    Gets or sets the double value that represents the y2 position of the annotation.

    Declaration
    public double Y2 { get; set; }
    Property Value
    Type Description
    System.Double

    This property takes the double as its value and its default value is double.NaN.

    Examples
    • Xaml
    • C#
        <chart:SfCartesianChart>
    
        <!-- ... Eliminated for simplicity-->
        <chart:SfCartesianChart.Annotations>
             <chart:LineAnnotation X1="1" Y1="10" X2="4" Y2="20"/>
        </chart:SfCartesianChart.Annotations>  
    
        </chart:SfCartesianChart>
        SfCartesianChart chart = new SfCartesianChart();     
    
        // Eliminated for simplicity
        var line = new LineAnnotation()
        {
            X1 = 1,
            Y1 = 10,
            X2 = 4,
            Y2 = 20,   
        };
    
        chart.Annotations.Add(line);

    Methods

    Draw(ICanvas, RectF)

    Draws the annotation of the chart.

    Declaration
    protected override void Draw(ICanvas canvas, RectF dirtyRect)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.ICanvas canvas
    Microsoft.Maui.Graphics.RectF dirtyRect
    Overrides
    ChartAnnotation.Draw(ICanvas, RectF)
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved