Posted by: Cirilo Meggiolaro | 01/9/2009

Tip of the day #87 – Exploring the Microsoft Chart control – Legends

Let’s check today the Legend class that compounds the Legends collection available on the Microsoft Chart control.

The idea of the legend is to provide information about a data series or fixed texts and built-in keywords that allow you retrieve information about the series values.

You may have unlimited legends on your chart and display them as a row, a column or a table. The legends accept custom positioning and docking inside or outside the chart area and also have an interactive functionality where you can display a checkbox to help you display / hide a data series.

Let´s check the main properties of the legends and some examples:

Properties

The following properties are available under a Legend object;

  • StringAlignment Alignment: Gets or sets the alignment of the legend;
  • int AutoFitMinFontSize: Gets or sets the minimum font size that can be used by the autofitting algorithm for the legend text;
  • Color BackColor: Gets or sets the background color of a legend;
  • GradientStyle BackGradientStyle: Gets or sets the orientation for the background gradient of a legend. If set to None, a gradient is not used;
  • ChartHatchStyle BackHatchStyle: Gets or sets the hatching style of a legend;
  • string BackImage: Gets or sets the background image of a legend;
  • ChartImageAlignmentStyle BackImageAlignment: Gets or sets the background image alignment when the drawing mode is “unscaled”;
  • Color BackImageTransparentColor: Gets or sets the color that will be replaced with a transparent color when the background image is drawn;
  • ChartImageWrapMode BackImageWrapMode: Gets or sets the legend background image drawing mode;
  • Color BackSecondaryColor: Gets or sets the secondary color of a legend background;
  • Color BorderColor: Gets or sets the border color of a legend;
  • ChartDashStyle BorderDashStyle: Gets or sets the border style of a legend such as solid, dot, dash and so on;
  • int BorderWidth: Gets or sets the border width of a legend;
  • LegendCellColumnCollection CellColumns: Read-only property that retrieves a collection of LegendCellColumn objects;
  • LegendItemsCollection CustomItems: Read-only property that retrieves a collection of legend items used for custom legends;
  • string DockedToChartArea: Gets or sets the name of the chart area where the legend will be docked;
  • Docking Docking: Gets or sets a value that specifies where the legend is docked;
  • bool Enabled: Gets or sets a flag that specifies whether the legend is enabled or not;
  • Font Font: Gets or sets the font that is used for the legend;
  • Color ForeColor: Gets or sets the color of the legend text;
  • LegendSeparatorStyle HeaderSeparator: Gets or sets the visual separator type for the legend header;
  • Color HeaderSeparatorColor: Gets or sets the color of the separator for the legend header;
  • string InsideChartArea: Gets or sets the name of the chart area in which the legend belongs to;
  • bool InterlacedRows: Gets or sets a flag that indicates if legend rows will be drawn with interlaced background color;
  • Color InterlacedRowsColor: Gets or sets the background color of the legend’s interlaced rows;
  • bool IsDockedInsideChartArea: Gets or sets a flag that indicates whether the legend is docked inside or outside the chart area;
  • bool IsEquallySpacedItems: Gets or sets a flag that indicates whether all legend items are equally spaced;
  • bool IsTextAutoFit: Gets or sets a flag that specified whether the text is adjusted automatically to fit;
  • LegendSeparatorStyle ItemColumnSeparator: Gets or sets the visual separator type for the legend table columns;
  • Color ItemColumnSeparatorColor: Gets or sets the color of the legend table column separator;
  • int ItemColumnSpacing: Gets or sets the legend table column spacing;
  • LegendItemOrder LegendItemOrder: Gets or sets the order in which the legend items are displayed. It may be in the same order than the values are added, the reverse order or automatically;
  • LegendStyle LegendStyle: Gets or sets the style of the legend;
  • float MaximumAutoSize: Gets or sets the maximum legend size (percentage of the chart area);
  • string Name: Gets or sets the name of the legend;
  • ElementPosition Position: Gets or sets the ElementPosition object, which can be used to get or set the position of the legend;
  • Color ShadowColor: Gets or sets the shadow color of the legend;
  • int ShadowOffset: Gets or sets the shadow offset, in pixels, of the legend;
  • LegendTableStyle TableStyle: Gets or sets the legend table style;
  • int TextWrapThreshold: Gets or sets the number of characters that can be sequentially displayed in the legend before the text is wrapped;
  • string Title: Gets or sets the text of the legend title;
  • StringAlignment TitleAlignment: Gets or sets the alignment of the legend title;
  • Color TitleBackColor: Gets or sets the background color of the legend title;
  • Font TitleFont: Gets or sets the font for the legend title;
  • Color TitleForeColor: Gets or sets the text color of the legend title;
  • LegendSeparatorStyle TitleSeparator: Gets or sets the visual separator type for the legend title;
  • Color TitleSeparatorColor: Gets or sets the color of the legend title separator.

Examples

The first example displays a chart with two data series and a simple legend displayed with the LegendStyle property set as a row.

Picture 1 - A simple legend that displays the series name.

Picture 1 - A simple legend that displays the series name.

The next picture displays a pie chart with a legend displayed as a row with the items being displayed. The legend contains a title, the Alignment property is set as Center and the Docking property is set as Bottom.

Picture 2 - A pie chart displaying points name.

Picture 2 - A pie chart displaying points name.


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: