Class AmLegend

AmLegend is the class that displays legend of the chart. Legend to the chart should be added using chart.addLegend(legend) method.

example

var chart = new AmCharts.AmSerialChart(); var legend = new AmCharts.AmLegend(); chart.addLegend(legend);

Hierarchy

Index

Properties

Methods

Properties

public align: string

Alignment of legend entries. Possible values are: "left", "center", "right". left

public autoMargins: boolean

Used if chart is Serial or XY. In case true, margins of the legend are adjusted and made equal to chart's margins.

default

true

public backgroundAlpha: number

Opacity of legend's background. Value range is 0 - 1

public backgroundColor: string

Background color. You should set backgroundAlpha to >0 vallue in order background to be visible. #FFFFFF

public borderAlpha: number

Opacity of chart's border. Value range is 0 - 1.

public borderColor: string

Color of legend's border. You should set borderAlpha >0 in order border to be visible. #000000

public bottom: number

In case legend position is set to "absolute", you can set distance from bottom of the chart, in pixels.

public color: string

Text color. Will use chart's color if not set.

public data: Array<any>

This can be used by AmMap only. You can pass array of objects with title, color, markerType values, for example: [{title: "One", color: "#3366CC"},{title: "Two", color: "#FFCC33"}]

public equalWidths: boolean

Specifies if each of legend entry should be equal to the most wide entry. Won't look good if legend has more than one line.

default

true

public fontSize: number

Font size. Will use chart's font size if not set.

public horizontalGap: number

Horizontal space between legend item and left/right border.

public labelText: string

The text which will be displayed in the legend. Tag title will be replaced with the title of the graph. title

public left: number

In case legend position is set to "absolute", you can set distance from left side of the chart, in pixels.

public marginBottom: number

Bottom margin.

public marginLeft: number

Left margin. This property will be ignored if chart is Serial or XY and autoMargins property of the legend is true (default).

default

20

public marginRight: number

Right margin. This property will be ignored if chart is Serial or XY and autoMargins property of the legend is true (default).

default

20

public marginTop: number

Top margin.

public markerBorderAlpha: number

Marker border opacity 1.

public markerBorderColor: string

Marker border color. If not set, will use the same color as marker.

public markerBorderThickness: number

Thickness of the legend border. The default value (0) means the line will be a "hairline" (1 px). In case marker type is line, this style will be used for line thickness.

default

1

public markerDisabledColor: string

The color of the disabled marker (when the graph is hidden). #AAB3B3

public markerLabelGap: number

Space between legend marker and legend text, in pixels.

default

5

public markerSize: number

Size of the legend marker (key).

default

16

public markerType: string

Shape of the legend marker (key). Possible values are: "square", "circle", "line", "dashedLine", "triangleUp", "triangleDown", "bubble", "none". square

public maxColumns: number

Maximum number of columns in the legend. If Legend's position is set to "right" or "left", maxColumns is automatically set to 1.

public position: string

Position of a legend. Possible values are: "bottom", "top", "left", "right" and "absolute". In case "absolute", you should set left and top properties too. (this setting is ignored in Stock charts). In case legend is used with AmMap, position is set to "absolute" automatically. bottom

public reversedOrder: boolean

Specifies whether legend entries should be placed in reversed order.

public right: number

In case legend position is set to "absolute", you can set distance from right side of the chart, in pixels.

public rollOverColor: string

Legend item text color on roll-over. #CC0000

public rollOverGraphAlpha: number

When you roll-over the legend entry, all other graphs can reduce their opacity, so that the graph you rolled-over would be distinguished. This style specifies the opacity of the graphs.

default

1

public showEntries: boolean

You can use this property to turn all the legend entries off.

default

true

public spacing: number

Horizontal space between legend items, in pixels.

default

10

public switchColor: string

Legend switch color. #FFFFFF

public switchType: string

Legend switch type (in case the legend is switchable). Possible values are "x" and "v". x

public switchable: boolean

Whether showing/hiding of graphs by clicking on the legend marker is enabled or not. In case legend is used with AmMap, this is set to false automatically.

default

true

public textClickEnabled: boolean

If true, clicking on the text will show/hide balloon of the graph. Otherwise it will show/hide graph/slice, if switchable is set to true.

public top: number

In case legend position is set to "absolute", you can set distance from top of the chart, in pixels.

public useMarkerColorForLabels: boolean

Specifies if legend labels should be use same color as corresponding markers.

public valueAlign: string

Alignment of the value text. Possible values are "left" and "right". right

public valueText: string

The text which will be displayed in the value portion of the legend. You can use tags like value, [[open]], [[high]], [[low]], [[close]], percents, description. value

public valueWidth: number

Width of the value text.

default

80

public verticalGap: number

Vertical space between legend items also between legend border and first and last legend row. 10

Methods

public addListener(type: string, handler: (e: { type: string; dataItem: Object; chart: AmCharts.AmChart; }) => void): any

Adds event listener of the type "showItem" to the object.

Parameters

  • type: string

    Always "showItem".

  • handler: (e: { type: string; dataItem: Object; chart: AmCharts.AmChart; }) => void

Returns

any

public removeListener(chart: AmChart, type: string, handler: any): any

Removes event listener from chart object.

Parameters

  • chart: AmChart
  • type: string
  • handler: any

Returns

any