Chart for .NET / User's Guide / Legend / Legend Layout

In This Topic
    Legend Layout
    In This Topic
     Legend Data Item Expand Strategy

    When you add new items to the NLegendData object the legend may become too long to display in the control canvas. This is why 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 NLegendData controls this. The following table list the possible strategies:

    LegendExpandMode Description
    RowsOnly The legend expands by adding new rows only and there is only one column.
    ColsOnly The legend expands by adding new columns only and there is only one row.
    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.
    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.
    HorzWrap The legend tries to fit in the assigned bounds by increasing the number of rows and then the number of columns.
    VertWrap The legend tries to fit in the assigned bounds by increasing the number of columns and then the number of rows.

    The following example shows this:

    C#
    Copy Code
    legend.Data.ExpandMode = LegendExpandMode.RowsFixed;
    legend.Data.RowCount = 4;
    
    Visual Basic
    Copy Code
    legend.Data.ExpandMode = LegendExpandMode.RowsFixed
    legend.Data.RowCount = 4
    

    If you have 12 data items in the legend this layout will produce a legend similar to this one:

     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. This is where the predefined legend styles can come handy.

    You apply a predefined legend style to the legend by using the SetPredefinedLegendStyle method of the of the NLegend object. For instance:

    C#
    Copy Code
    legend.SetPredefinedLegendStyle(PredefinedLegendStyle.Bottom);
    
    Visual Basic
    Copy Code
    legend.SetPredefinedLegendStyle(PredefinedLegendStyle.Bottom)
    

    The following table lists the available legend styles:

    Predefined legend style Description
    PredefinedLegendStyle.Top

    Positions the legend at the top of the control window and allows the legend to expand by adding columns only.

    PredefinedLegendStyle.Bottom Positions the legend at the bottom of the control window and allows the legend to expand by adding columns only.
    PredefinedLegendStyle.Left Positions the legend at the left side of the control window and allows the legend to expand by adding rows only.
    PredefinedLegendStyle.Right Positions the legend at the right side of the control window and allows the legend to expand by adding rows only.
    PredefinedLegendStyle.TopRight Positions the legend at the top right side of the control window and allows the legend to expand by adding rows only.
    PredefinedLegendStyle.TopLeft Positions the legend at the top left side of the control window and allows the legend to expand by adding rows only.

    Related Examples

    Windows Forms: Legend\Position and Style

    Web Forms: Legend\Position and Style

    SectionId
    See Also