Posted by: Cirilo Meggiolaro | 01/10/2009

Tip of the day #88 – Exploring the Microsoft Chart control – Annotations

Let’s check today the Microsoft Chart annotation feature.

Annotations

Annotations are some piece of information that you may display for chart elements. You may display text, images or built-in arrows anchored to data points for example to give details about a specific data point.

Annotation Types

Different from the other objects we’ve seen this week, the Annotation is an abstract class. So, to define an annotation type, you won’t set a property but instantiate an extended type. The following classes are available:

  • LineAnnotation;
  • VerticalLineAnnotation;
  • HorizontalLineAnnotation;
  • TextAnnotation;
  • RectangleAnnotation;
  • EllipseAnnotation;
  • ArrowAnnotation;
  • Border3DAnnotation;
  • CalloutAnnotation;
  • PolylineAnnotation;
  • PolygonAnnotation;
  • ImageAnnotation;
  • AnnotationGroup.

Once there’s no annotation type property to set, if you want to add an annotation in design type, you need to add a specific type. To check that:

  • Select a chart control previously added to your form;
  • Click on the three dots button right to the Annotations property on the Properties Window. The Annotation Collection Editor will be displayed;
  • You may realize that the Add button is a dropdown button. Click on the bottom arrow to display all the annotation types available.

The following picture shows the options:

Picture 1 - The annotation types available under the Add dropdown button.

Picture 1 - The annotation types available under the Add dropdown button.

After you select an annotation type different properties will be available. The next list shows the common ones:

  • ContentAlignment Alignment: Gets or sets the internal alignment of an annotation;
  • bool AllowAnchorMoving: Gets or sets a flag that specifies whether the end user is allowed to move the annotation anchor;
  • bool AllowMoving: Gets or sets a flag that specifies whether the end user is allowed to move an annotation;
  • bool AllowPathEditing: Gets or sets a flag that specifies whether the end user is allowed to move the points of a polygon annotation;
  • bool AllowResizing: Gets or sets a flag that specifies whether the end user is allowed to resize an annotation;
  • bool AllowSelecting: Gets or sets a flag that specifies whether the end user is allowed to select an annotation;
  • bool AllowTextEditing: Gets or sets a flag that specifies whether the text in an annotation may be edited when the end user double clicks the text;
  • ContentAlignment AnchorAlignment: Gets or sets the alignment of an annotation to the anchor point;
  • DataPoint AnchorDataPoint: Gets or sets the data point to which an annotation is anchored;
  • double AnchorOffsetX: Gets or sets the offset from the anchor point for the X position of an annotation;
  • double AnchorOffsetY: Gets or sets the offset from the anchor point for the Y position of an annotation;
  • double AnchorX: Gets or sets the X coordinate to which the annotation is anchored;
  • double AnchorY: Gets or sets the Y coordinate to which the annotation is anchored;
  • Axis AxisX: Gets or sets the X axis to which an annotation is attached;
  • Axis AxisY: Gets or sets the Y axis to which an annotation is attached;
  • Color BackColor: Gets or sets the color of an annotation background;
  • GradientStyle BackGradientStyle: Gets or sets the gradient style of an annotation background;
  • ChartHatchStyle BackHatchStyle: Gets or sets the hatching style of an annotation background;
  • Color BackSecondaryColor: Gets or sets the secondary color of an annotation background;
  • double Bottom: Gets or sets the bottom boundary of an annotation position;
  • string ClipToChartArea: Gets or sets the name of the chart area to which an annotation is clipped;
  • Font Font: Gets or sets the font used to display the annotation text;
  • Color ForeColor: Gets or sets the text color of an annotation;
  • double Height: Gets or sets the height of an annotation;
  • bool IsSelected: Gets or sets a flag that determines if an annotation is selected;
  • bool IsSizeAlwaysRelative: Gets or sets a flag that specifies whether the size of an annotation is always defined in relative chart coordinates;
  • Color LineColor: Gets or sets the line color of an annotation;
  • ChartDashStyle LineDashStyle: Gets or sets the line style of an annotation;
  • int LineWidth: Gets or sets the line width of an annotation;
  • string Name: Gets or sets the unique name of an annotation;
  • double Right: Gets or sets the right boundary position of an annotation;
  • Color ShadowColor: Gets or sets the color of an annotation’s shadow;
  • int ShadowOffset: Gets or sets the size of an annotation’s shadow;
  • AnnotationSmartLabelStyle SmartLabelStyle: Gets or sets the smart label style of an annotation;
  • TextStyle TextStyle: Gets or sets the text style of an annotation;
  • string ToolTip: Gets or sets the tooltip text for an annotation;
  • bool Visible: Gets or sets a flag that specifies whether an annotation is visible;
  • double Width: Gets or sets the width of an annotation (pixels);
  • double X: Gets or sets the X position of an annotation;
  • double Y: Gets or sets the Y position of an annotation.

Example

The following picture shows two annotations added to a chart control:

  1. Displays a callout annotation anchored to a data point;
  2. Displays an image annotation with a custom image anchored to a data point.
Picture 2 - Chart control with two annotations.

Picture 2 - Chart control with two annotations.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: