When you add new items to the LegendData object, the legend may become too long to display in the control window or image. For this reason you may wish to alter the legend layout strategy or, in other words, the way the legend expands when new items are added. The ExpandMode property of the LegendData controls this. The following table lists the possible strategies (for details, see LegendExpandMode Enumeration):
Expand mode
Description
LegendExpandMode.RowsOnly
The legend expands by adding new rows only and there is only one column.
LegendExpandMode.ColsOnly
The legend expands by adding new columns only and there is only one row.
LegendExpandMode.RowsFixed
The legend expands by adding new rows until it reaches the value RowCount (which is initially 10) and then adds a new column. In other words, the row count is limited and the column count is unlimited.
LegendExpandMode.ColsFixed
The legend expands by adding new columns until it reaches the value ColCount (which is initially 10) and then adds a new row. In other words, the column count is limited and the row count is unlimited.
If you have 12 data items in the legend, this layout will produce a legend similar to this one:
Position
The legend's position is controlled with the HorizontalMargin, VerticalMargin, HorzAlign, and VertAlign properties of the Legend object. The first two define the margins of the legend in percent values of the control window dimensions, and the latter two how the legend should align to the margins. The following table shows how these properties work together to determine the final legend position:
Left Horizontal and Top Vertical Align
Center Vertical and Horizontal Align
The blue lines represent the position defined by the HorizontalMargin and VerticalMargin properties.
Predefined Legend Styles
Often you need to alter both the legend position (by default at the right top edge of the control window) and the legend expand mode. For example, consider that you want to display the following chart:
You can avoid having to write the code required to position the legend at the bottom, align it properly, and then change the expand mode to ColsOnly by using the SetPredefinedLegendStyle method of the of the Legend object. For instance: