Information on this website refers to a deprecated product, and is provided only for historical reference. Please use the Version Switcher above to select an appropriate documentation website for the product you are using.

AmLegend

Type class

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

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

In case legend is used with AmMap, you should provide data to the legend:

legend.data = [{title:"first", color:"#CC0000"}, {title:"second", color:"#00CC00"}]

However in most cases ValueLegend is more useful for AmMap.

Inheritance

AmLegend does not extend any other symbol.

AmLegend is extended by StockLegend.

Properties

align
#

Type string

Default left

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

autoMargins
#

Type boolean

Default true

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

backgroundAlpha
#

Type number

Default 0

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

backgroundColor
#

Type string

Default #FFFFFF

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

borderAlpha
#

Type number

Default 0

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

borderColor
#

Type string

Default #000000

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

bottom
#

Type number

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

color
#

Type Hex string

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

data
#

Type array

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"}]

equalWidths
#

Type boolean

Default true

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.

fontSize
#

Type number

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

horizontalGap
#

Type number

Default 0

Horizontal space between legend item and left/right border.

labelText
#

Type string

Default [[title]]

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

left
#

Type number

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

marginBottom
#

Type number

Default 0

Bottom margin.

marginLeft
#

Type number

Default 20

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

marginRight
#

Type number

Default 20

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

marginTop
#

Type number

Default 0

Top margin.

markerBorderAlpha
#

Type number

Default 1

Marker border opacity.

markerBorderColor
#

Type Hex string

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

markerBorderThickness
#

Type number

Default 1

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.

markerDisabledColor
#

Type Hex string

Default #AAB3B3

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

markerLabelGap
#

Type number

Default 5

Space between legend marker and legend text, in pixels.

markerSize
#

Type number

Default 16

Size of the legend marker (key).

markerType
#

Type string

Default square

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

maxColumns
#

Type number

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

position
#

Type string

Default bottom

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.

reversedOrder
#

Type boolean

Default false

Specifies whether legend entries should be placed in reversed order.

right
#

Type number

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

rollOverColor
#

Type string

Default #CC0000

Legend item text color on roll-over.

rollOverGraphAlpha
#

Type number

Default 1

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.

showEntries
#

Type boolean

Default true

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

spacing
#

Type number

Default 10

Horizontal space between legend items, in pixels.

switchable
#

Type boolean

Default true

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.

switchColor
#

Type Hex string

Default #FFFFFF

Legend switch color.

switchType
#

Type string

Default x

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

textClickEnabled
#

Type boolean

Default false

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.

top
#

Type number

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

useMarkerColorForLabels
#

Type boolean

Default false

Labels will use marker color if you set this to true.

useMarkerColorForValues
#

Type boolean

Default false

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

valueAlign
#

Type string

Default right

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

valueText
#

Type string

Default [[value]]

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]].

valueWidth
#

Type number

Default 80

Width of the value text.

verticalGap
#

Type number

Default 10

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

Methods

addListener(
  type,
  handler
)

#

Returns void

Adds event listener to the object.

type - string like 'clickLabel' (should be listed in 'events' section of this class or classes which extend this class). handler - function which is called when event happens

removeListener(
  legend,
  type,
  handler
)

#

Returns void

Removes event listener from the legend object.

Events

#clickLabel

Param {type:"clickLabel", dataItem:Object, chart:AmChart}

Dispatched when legend label is clicked.

#clickMarker

Param {type:"clickMarker", dataItem:Object, chart:AmChart}

Dispatched when legend marker is clicked.

#hideItem

Param {type:"hideItem", dataItem:Object, chart:AmChart}

Dispatched when user clicks on a legend item marker and hides corresponding object.

#rollOutItem

Param {type:"rollOutItem", dataItem:Object, chart:AmChart}

Dispatched when user rolls-out of the legend item label (or whole item, if switchable is set to false).

#rollOverItem

Param {type:"rollOverItem", dataItem:Object, chart:AmChart}

Dispatched when user rolls-over the legend item label (or whole item, if switchable is set to false).

#rollOverMarker

Param {type:"rollOverMarker", dataItem:Object, chart:AmChart}

Dispatched when user rolls-over the legend item marker.

#showItem

Param {type:"showItem", dataItem:Object, chart:AmChart}

Dispatched when user clicks on a legend item marker and shows corresponding object.

Adapters

AmLegend does not have any adapters.