ChartDirector 5.1 (PHP Edition)

LegendBox


The class LegendBox represents legend boxes. It is a subclass of TextBox.

Use BaseChart.addLegend or BaseChart.addLegend2 to add legend boxes to charts.

By default, ChartDirector will add named data representation to the legend box. For pie charts, named sectors (sectors that have text labels) will be added. For xy charts, named data sets will be added. For polar charts, named layers will be added.

You may add custom entries to the legend box by using LegendBox.addKey or LegendBox.addKey2.

To control the ordering of the legend entries, ChartDirector employs a legend entry priority system. Each entry is given a priority number, and the entries are ordered according to ascending priority (unless reversed by using LegendBox.setReverse).

For a PieChart, the legend entry priority of a sector is 10000 x (sector_index + 1). The Nth sector has sector_index (N - 1). That means the ordering of the sectors in the legend box is the same as the data array.

For an XYChart, the base legend entry priority for a layer is 10000 x (layer_index + 1). Within a layer, the data set priority is 10 x (data_set_index + 1). For example, the legend entry priority for the 5th dataset in the 3rd layer will be 30050. That means the ordering of the data sets in the legend box follows the order in which the layers are created. For data sets within the same layer, the ordering follows the order in which the data sets are added. The ordering can be modified by using Layer.setLegendOrder.

For an PolarChart, the legend entry priority of a layer is 10000 x (layer_index + 1). That means the ordering of the layers in the legend box follows the order in which the layers are created.

For custom entries added using LegendBox.addKey2, you may control the legend entry priority. That means you may insert custom entries anywhere relative to the automatic entries added by ChartDirector.

MethodInheritedDescription
addKey(Self)Adds a custom entry to the legend box.
addKey2(Self)Adds a custom entry to the legend box with a given legend entry priority.
setCols(Self)Sets the number of columns in the legend box.
setReverse(Self)Reverses the ordering of the legend entries.
setText(Self)Sets the template of the legend text.
setKeySize(Self)Sets the size of the legend icon and its distance from the legend text.
setKeySpacing(Self)Sets the distance between two legend entries.
setKeyBorder(Self)Sets the default border color of the legend icon.
setLineStyleKey(Self)Determines whether to always use "line style legend keys" or not.
getImageCoor2(Self)Gets the image map coordinates of an legend entry as HTML image map attributes.
getHTMLImageMap(Self)Generates an HTML image map for the legend box.
setFontStyleTextBoxSets the font of the text by specifying the file that contains the font.
setFontSizeTextBoxSets the font height and width in points.
setFontAngleTextBoxSets the rotation angle and layout direction of the text.
setFontColorTextBoxSets the color of the text.
setAlignmentTextBoxSets the alignment of the text relative to the container box.
setWidthTextBoxSets the width of the text box and wraps text if necessary.
setHeightTextBoxSets the height of the text box.
setMaxWidthTextBoxSets the maximum width of the text box and wraps text if necessary.
setTruncateTextBoxSets the maximum number of lines in the text box, and truncate the text if it exceeds the line count.
setMarginTextBoxSets all margins (left, right, top, and bottom) of the text box to the same value.
setMargin2TextBoxSets the margins of the text box.
setPosBoxSets the coordinates of the reference point of the box, which by default is the top-left corner of the box.
setSizeBoxSets the width and height of the box.
setBackgroundBoxSets the background color, border color and 3D border effect of the box.
setRoundedCornersBoxSets the border style to use rounded corners.
getLeftXBoxGets the left x pixel coordinate of the box.
getTopYBoxGets the top y pixel coordinate of the box.
getWidthBoxGets the width of the box.
getHeightBoxGets the height of the box.
getImageCoorBoxGets the image map coordinates of the box as HTML image map attributes.
setZOrderBoxSets the z-order (drawing order) for custom box objects.