AmLegend
Type class
Creates the legend for the chart, automatically adapts the color settings of the graphs.
Example
```js var chart = AmCharts.makeChart("chartdiv",{ ... "legend": { "useGraphSettings": true }, });```Sources
This information about AmLegend is provided for reference only and is not available through exported packages and thus should not be imported or used on its own.
Inheritance
AmLegend does not extend any other symbol.
AmLegend is extended by StockLegend.
Properties
accessibleLabelType
stringDefault[[title]]Text which screen readers will read if user rolls-over the element or sets focus on it using tab key (this is possible only if tabIndex property of AmLegend is set to some number). Text is added as aria-label tag. Note - not all screen readers and browsers support this.
alignType
stringDefaultleftAlignment of legend entries. Possible values are: "left", "center", "right".
autoMarginsType
booleanDefaulttrueUsed if chart is Serial or XY. In case true, margins of the legend are adjusted and made equal to chart's margins.
backgroundAlphaType
numberDefault0Opacity of legend's background. Value range is 0 - 1
backgroundColorType
colorDefault#FFFFFFBackground color. You should set backgroundAlpha to >0 vallue in order background to be visible.
borderAlphaType
numberDefault0Opacity of chart's border. Value range is 0 - 1.
borderColorType
colorDefault#000000Color of legend's border. You should set borderAlpha >0 in order border to be visible.
bottomType
numberIn case legend position is set to "absolute", you can set distance from bottom of the chart, in pixels.
colorType
colorDefault#000000Text color.
combineLegendType
booleanDefaultfalseIf you set it to true, and you have some legend items set using legend.data property, both graph’s entries and those added using data property will be displayed.
dataType
object[]You can pass array of objects with title, color, markerType values, for example: [{title: "One", color: "#3366CC"},{title: "Two", color: "#FFCC33"}]
divIdType
stringYou can set id of a div or a reference to div object in case you want the legend to be placed in a separate container.
enabledType
booleanDefaulttrueSpecifies if legend is enabled or not.
equalWidthsType
booleanDefaulttrueSpecifies if each of legend entry should be equal to the most wide entry. Won't look good if legend has more than one line.
fontSizeType
numberDefault11Font size.
forceWidthType
booleanDefaultfalseIf you set this property to true, width of legend item labels won't be adjusted. Useful when you have more than one chart and want to align all the legends.
gradientRotationType
numberCan be used if legend uses custom data. Set it to 0, 90, 180 or 270.
horizontalGapType
numberDefault0Horizontal space between legend item and left/right border.
labelTextType
stringDefault[[title]]The text which will be displayed in the legend. Tag
titlewill be replaced with the title of the graph.labelWidthType
numberIf width of the label is bigger than labelWidth, it will be wrapped.
leftType
numberIn case legend position is set to "absolute", you can set distance from left side of the chart, in pixels.
listenersType
object[]You can add listeners of events using this property. Example: listeners = [{"event":"clickLabel", "method":handleEvent}];
marginBottomType
numberDefault0Bottom margin.
marginLeftType
numberDefault20Left margin. This property will be ignored if chart is Serial or XY and autoMargins property of the legend is true (default).
marginRightType
numberDefault20Right margin. This property will be ignored if chart is Serial or XY and autoMargins property of the legend is true (default).
marginTopType
numberDefault0Top margin.
markerBorderAlphaType
numberDefault1Marker border opacity.
markerBorderColorType
colorMarker border color. If not set, will use the same color as marker.
markerBorderThicknessType
numberDefault1Thickness 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.
markerDisabledColorType
colorDefault#AAB3B3The color of the disabled marker (when the graph is hidden).
markerLabelGapType
numberDefault5Space between legend marker and legend text, in pixels.
markerSizeType
numberDefault16Size of the legend marker (key).
markerTypeType
stringDefaultsquareShape of the legend marker (key). Possible values are: square, circle, diamond, triangleUp, triangleDown, triangleLeft, triangleDown, bubble, line, none.
maxColumnsType
numberMaximum number of columns in the legend. If Legend's position is set to "right" or "left", maxColumns is automatically set to 1.
periodValueTextType
stringThe text which will be displayed in the value portion of the legend when user is not hovering above any data point. The tags should be made out of two parts - the name of a field (value / open / close / high / low) and the value of the period you want to be show - open / close / high / low / sum / average / count. For example:
value.summeans that sum of all data points of value field in the selected period will be displayed.positionType
stringDefaultbottomPosition 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.
reversedOrderType
booleanDefaultfalseSpecifies whether legend entries should be placed in reversed order.
rightType
numberIn case legend position is set to "absolute", you can set distance from right side of the chart, in pixels.
rollOverColorType
colorDefault#CC0000Legend item text color on roll-over.
rollOverGraphAlphaType
numberDefault1When 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 non-hovered graphs.
showEntriesType
booleanDefaulttrueYou can use this property to turn all the legend entries off.
spacingType
numberDefault10Horizontal space between legend items, in pixels.
switchableType
booleanDefaulttrueWhether 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.
switchColorType
colorDefault#FFFFFFLegend switch color.
switchTypeType
stringDefaultxLegend switch type (in case the legend is switchable). Possible values are "x" and "v".
tabIndexType
numberIn case you set it to some number, the chart will set focus on legend entry when user clicks tab key. When a focus is set, screen readers like NVDA Screen reader will read label which is set using accessibleLabel property of AmLegend. If legend has switchable set to true, pressing Enter (Return) key will show/hide the graph. Note, not all browsers and readers support this.
textClickEnabledType
booleanDefaultfalseIf 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.
topType
numberIn case legend position is set to "absolute", you can set distance from top of the chart, in pixels.
useGraphSettingsType
booleanDefaultfalseLegend markers can mirror graph’s settings, displaying a line and a real bullet as in the graph itself. Set this property to true if you want to enable this feature. Note, if you set graph colors in dataProvider, they will not be reflected in the marker.
useMarkerColorForLabelsType
booleanDefaultfalseLabels will use marker color if you set this to true.
useMarkerColorForValuesType
booleanDefaultfalseSpecifies if legend values should be use same color as corresponding markers.
valueAlignType
stringDefaultrightAlignment of the value text. Possible values are "left" and "right".
valueFunctionYou can use it to format value labels in any way you want. Legend will call this method and will pass GraphDataItem and formatted text of currently hovered item (works only with ChartCursor added to the chart). This method should return string which will be displayed as value in the legend.
valueTextType
stringDefault[[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.valueWidthType
numberDefault50Width of the value text.
verticalGapType
numberDefault10Vertical space between legend items also between legend border and first and last legend row.
widthType
numberWidth of a legend, when position is set to absolute.
Methods
addListener()Returns
voidAdds 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()Returns
voidRemoves event listener from the legend object.
Events
clickLabelParam { type:
"clickLabel", target:AmLegend} &{type:"clickLabel", dataItem:Object, chart:AmChart}Dispatched when legend label is clicked.
clickMarkerParam { type:
"clickMarker", target:AmLegend} &{type:"clickMarker", dataItem:Object, chart:AmChart}Dispatched when legend marker is clicked.
hideItemParam { type:
"hideItem", target:AmLegend} &{type:"hideItem", dataItem:Object, chart:AmChart}Dispatched when user clicks on a legend item marker and hides corresponding object.
rollOutItemParam { type:
"rollOutItem", target:AmLegend} &{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).
rollOverItemParam { type:
"rollOverItem", target:AmLegend} &{type:"rollOverItem", dataItem:Object, chart:AmChart}Dispatched when user rolls-over the legend item label (or whole item, if switchable is set to false).
rollOverMarkerParam { type:
"rollOverMarker", target:AmLegend} &{type:"rollOverMarker", dataItem:Object, chart:AmChart}Dispatched when user rolls-over the legend item marker.
showItemParam { type:
"showItem", target:AmLegend} &{type:"showItem", dataItem:Object, chart:AmChart}Dispatched when user clicks on a legend item marker and shows corresponding object.