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.
Method | Inherited | Description |
---|---|---|
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. |
setFontStyle | TextBox | Sets the font of the text by specifying the file that contains the font. |
setFontSize | TextBox | Sets the font height and width in points. |
setFontAngle | TextBox | Sets the rotation angle and layout direction of the text. |
setFontColor | TextBox | Sets the color of the text. |
setAlignment | TextBox | Sets the alignment of the text relative to the container box. |
setWidth | TextBox | Sets the width of the text box and wraps text if necessary. |
setHeight | TextBox | Sets the height of the text box. |
setMaxWidth | TextBox | Sets the maximum width of the text box and wraps text if necessary. |
setTruncate | TextBox | Sets the maximum number of lines in the text box, and truncate the text if it exceeds the line count. |
setMargin | TextBox | Sets all margins (left, right, top, and bottom) of the text box to the same value. |
setMargin2 | TextBox | Sets the margins of the text box. |
setPos | Box | Sets the coordinates of the reference point of the box, which by default is the top-left corner of the box. |
setSize | Box | Sets the width and height of the box. |
setBackground | Box | Sets the background color, border color and 3D border effect of the box. |
setRoundedCorners | Box | Sets the border style to use rounded corners. |
getLeftX | Box | Gets the left x pixel coordinate of the box. |
getTopY | Box | Gets the top y pixel coordinate of the box. |
getWidth | Box | Gets the width of the box. |
getHeight | Box | Gets the height of the box. |
getImageCoor | Box | Gets the image map coordinates of the box as HTML image map attributes. |
setZOrder | Box | Sets the z-order (drawing order) for custom box objects. |