Export (0) Print
Expand All

Annotations in Chart Controls

The Chart.Annotations collection property contains all annotations (Annotation objects) in the Chart control. You can add different types of annotations to the collection. They are useful as comments in the chart picture to elaborate on data points. You can also use them to draw custom shapes (PolylineAnnotation, PolygonAnntation, or AnnotationGroup).

Note Note

Limitations apply when using annotations inside a 3D chart area. For more information, see 3D Charts.

There are different types of annotations:

  • Shape-only (such as LineAnnotation)

  • Text-only (such as TextAnnotation)

  • Text-and-shape (such as EllipseAnnotation)

  • Group (such as AnnotationGroup)

To add an annotation to the Chart control at run time, use the Add method in the Chart.Annotations object. The following code demonstrates adding a LineAnnotation to the Chart control.

Imports System.Web.UI.DataVisualization.Charting
...
Dim myLine as LineAnnotation  = New LineAnnotation()
myLine.Name = "myLine"
myLine.X = 3
myLine.Y = 3
Chart1.Annotations.Add(myLine)

Position an annotation in the following ways:

  • Position it anywhere in the chart picture using the Annotation.X and Annotation.Y properties.

  • Anchor it to a position in the chart picture using the Annotation.AnchorX and Annotation.AnchorY properties, then use smart labels to automatically position it around other labels. For more information, see Labels.

  • Anchor its X and Y coordinates to the X and Y axes in the plot area. To do this, set the Annotation.AxisX and Annotation.AxisY properties to the axes you want to use, and then specify the Annotation.AnchorX and Annotation.AnchorY properties.

    The following code uses the primary X and Y axes to position the annotation at axis coordinates (1,20) in the plot area.

    Chart1.Annotations(0).AxisX = Chart1.ChartAreas(0).AxisX;
    Chart1.Annotations(0).AxisY = Chart1.ChartAreas(0).AxisY;
    Chart1.Annotations(0).AnchorX = 1;
    Chart1.Annotations(0).AnchorY = 20;
    

    Chart1.Annotations[0].AxisX = Chart1.ChartAreas[0].AxisX;
    Chart1.Annotations[0].AxisY = Chart1.ChartAreas[0].AxisY;
    Chart1.Annotations[0].AnchorX = 1;
    Chart1.Annotations[0].AnchorY = 20;
    

  • Anchor the annotation to a data point with the Annotation.AnchorDataPoint property.

    The following code anchors the annotation to the second data point of the first series.

    Chart1.Annotations(0).AnchorDataPoint = Chart1.Series(0).Points(1)
    

    Chart1.Annotations[0].AnchorDataPoint = Chart1.Series[0].Points[1];
    

    NoteNote

    If you anchor the annotation to a data point, you can use the data point's keywords in the annotation's Text, Tooltip, Url, and MapAreaAttributes properties. For more information, see Keywords.

Size an annotation in the following ways:

  • Use Annotation.Width and Annotation.Height at design time.

  • Use Annotation.Right and Annotation.Bottom at run time.

Show:
© 2014 Microsoft