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).
|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)
Adding Annotations at Run Time
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.
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.AxisX = Chart1.ChartAreas.AxisX; Chart1.Annotations.AxisY = Chart1.ChartAreas.AxisY; Chart1.Annotations.AnchorX = 1; Chart1.Annotations.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.
Note: 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.