DrawLegend

Prototype

void DrawLegend( Plot plot, Matrix mLabels, int nLabelSize, Matrix mLineColor, Matrix mLineStyle, Matrix mSymbol, int nBackgroundColor, String sLocation )

Parameters

Plot plot
The plot to which the legend will be added.

Matrix mLabels
A character vector that specifies the labels for the items in the legend. The string mLabels[i] is the label for the ith item.

int nLabelSize
The point size (units of 1/72 inch) of the font used for the legend labels.

Matrix mLineColor
A numeric vector containing colors (as integers). The value mLineColor[i] is the color for the ith line or rectangle in the legend (see below). If mLineColor is a scalar, its value is used for all items. The predefined color constants are BLACK, BLUE, BROWN, CHARCOAL, CREAM, CYAN, GOLD, GRAY, GREY, GREEN, LILAC, LIME, MAGENTA, MAROON, OLIVE, ORANGE, PINK, PURPLE, RED, ROSE, SALMON, STEEL, TAN, VIOLET, WHITE, and YELLOW.

Matrix mLineStyle
A numeric vector in which the ith element specifies the line style for the ith line or rectangle in the legend. The valid line styles are SOLID, DASHED, DOTTED, DASHDOT, and DASHDOTDOT. If mLineStyle[i] is 0, a rectangle is drawn for the ith item instead of a line segment. If mLineStyle[i] is negative, neither a line segment nor a rectangle is drawn for the ith item. If mLineStyle is a scalar, its value is used for all items.

Matrix mSymbol
A numeric vector in which the ith element specifies the symbol for the ith item in the legend. The valid symbols are MARKER_SQUARE, MARKER_PLUS, MARKER_CIRCLE, MARKER_DIAMOND, MARKER_X, MARKER_TRIANGLE, MARKER_INVTRIANGLE, and MARKER_STAR. If mSymbol[i] is -1, no symbol is drawn for the ith item. If mSymbol is a scalar, its value is used for all items.

int nBackgroundColor
The background color of the legend. The predefined color constants are BLACK, BLUE, BROWN, CHARCOAL, CREAM, CYAN, GOLD, GRAY, GREY, GREEN, LILAC, LIME, MAGENTA, MAROON, OLIVE, ORANGE, PINK, PURPLE, RED, ROSE, SALMON, STEEL, TAN, VIOLET, WHITE, and YELLOW. If nBackgroundColor is -1, the legend will be transparent.

String sLocation
A three-character text string that specifies the position of the legend within the plot. This string has the form "PXY", where P is either I (inside the Plot Area) or O (outside the Plot Area), X is either L (left), C (center), or R (right), and Y is either T (top), C (center), or B (bottom). For example, common choices are "ILT" (upper left corner of the Plot Area), "ORC" (in the right graph margin), and "OCB" (in the bottom graph margin).

Remarks

This module draws a legend on a plot. The number of labels and the value of the nLabelSize parameter determine the size of the legend.

If the legend is positioned outside the Plot Area (for example, sLocation = "ORC"), the Graph Area margins are modified to accommodate the legend.

If the legend is centered in the horizontal direction (for example, sLocation = "OCB"), the items in the legend are arranged in multiple columns. Otherwise, the items are arranged in one column.

Example
declare DataObject dobj;
dobj = DataObject.CreateFromFile( "iris" );
dobj.GetVarData( "Species", species );
speciesName = { "Setosa", "Virginica", "Versicolor" };
speciesColor = RED || GREEN || BLUE;
do i = 1 to 3;
    obs = loc( species = speciesName[i] );
    dobj.SetMarkerFillColor( obs, speciesColor[i] );
end;
declare ScatterPlot plot;
plot = ScatterPlot.Create( dobj, "PetalLen", "PetalWid" );
plot.SetMarkerSize( 6 );
run DrawLegend( plot, speciesName, 12, speciesColor,
    -1, MARKER_SQUARE, -1, "ILT" );
See Also

DrawInset
DrawLegendEx