SetLegend
Prev | PHPlot Function Reference | Next

## SetLegend

SetLegend — Add text to a legend box

## Synopsis

    $plot->SetLegend($leg)

## Description

`SetLegend` sets the text to be displayed in the legend. A legend is often needed when a plot contains more than one data set, to identify the purpose of the different data sets being plotted. The legend text consists of multiple lines, with each line identifying one data set on the plot. PHPlot adds an identifying color box or shape marker next to each line in the legend.

## Parameters

`$leg`

  An array with each element containing the text for one line of the legend. Or, if not an array, the one line to be appended to the legend. See notes.

## Notes

By default, no legend is displayed.

The legend usually needs to contain one line of text for each data set plotted on the graph, in the same order as the data array. You can supply all the legend lines in a single call to SetLegend as an array, or you can build up the legend one line at a time with multiple calls to SetLegend, supplying one line per call (in the same order as the data sets in the data array).

Legend text lines are displayed in order from top to bottom in the legend. Each line has a color box or shape maker with the corresponding color from the data colors array. The colors used in the legend color boxes or shape markers are independent of any custom data color callback (see Section 4.5, “Custom Data Color Selection”).

To cancel a legend (perhaps as part of drawing multiple plots on an image), pass an empty array or NULL as `$leg`.

To control the legend position on the plot, use SetLegendPixels, SetLegendWorld, or the more general SetLegendPosition. You can control the text and color box or shape marker alignment within the legend using SetLegendStyle.

Use SetLegendUseShapes to select color boxes or shape markers in the legend.

## History

Accepting NULL as a valid argument value was added in PHPlot-5.3.1. Through PHPlot-5.3.0, passing NULL would cause an error.

Prev | Up | Next
SetLabelScalePosition | Home | SetLegendBgColor