Top
You are looking at an outdated 7.13.1 version of this document. Switch to the 8.0.1 version to see the up to date information.

class anychart.standalones.Legend Improve this Doc

Methods Overview

Specific settings
iconSize()Icon size.
inverted()Inverted settings.
items()Custom items.
itemsFormatter()Items formatter.
itemsSource()Items source.
itemsSourceMode()Items source mode.
paginator()Paginator settings.
title()Title settings.
titleFormat()Title format function.
titleSeparator()Title separator settings.
Advanced Text Settings
fontVariant()Font variant settings.
letterSpacing()Text letter spacing settings.
textDirection()Text direction settings.
textIndent()Text indent settings.
textOverflow()Text overflow settings.
textWrap()Text wrap settings.
useHtml()Text useHtml settings.
Base Text Settings
fontColor()Font color settings.
fontDecoration()Font decoration settings.
fontFamily()Font family settings.
fontOpacity()Font opacity settings.
fontSize()Font size settings.
fontStyle()Font style settings.
fontWeight()Font weight settings.
hAlign()Text horizontal align settings.
lineHeight()Text line height settings.
vAlign()Text vertical align settings.
Coloring
background()Background settings.
Events
disablePointerEvents()Pointer events settings.
listen()Adds an event listener.
listenOnce()Adds a single time event listener.
removeAllListeners()Removes all listeners.
unlisten()Removes the listener.
unlistenByKey()Removes the listener by the key.
Export
print()Prints all elements.
Interactivity
enabled()Element state (enabled or disabled).
hoverCursor()Cursor settings in hover mode.
selectable()Text selectable option.
tooltip()Tooltip settings
Size and Position
align()Align settings.
getRemainingBounds()Getter for remain bounds after legend.
height()Height settings.
iconTextSpacing()Spacing between icon and text.
itemsLayout()Items layout settings.
itemsSpacing()Items spacing settings.
margin()Margin settings.
padding()Padding settings.
parentBounds()Bounds settings.
position()Position settings.
width()Width settings.
zIndex()Z-index of the element.
Text Settings
textSettings()Text settings.
Miscellaneous
container()Legend container.
draw()Draw legend.

Methods Description

align

Getter for legend align settings.

Returns:

anychart.enums.Align string - Legend align.

Try it:

Setter for legend align settings.

Params:

Name Type Default Description
value anychart.enums.Align | string
"center"
Value to set.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

background

Getter for legend background.

Returns:

anychart.core.ui.Background - Current background settings.
Setter for legend background.

Params:

Name Type Default Description
value string | Object | null | boolean
true
Background setting.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

container

Getter for the legend current container.

Returns:

string Element - The current container.
Setter for the legend container.

Params:

Name Type Description
value string | Element The value to set.

Returns:

anychart.standalones.Legend - Self instance for method chaining.

Try it:

disablePointerEvents

Getter for the current pointer events.

Returns:

boolean - Flag of the current state.

Try it:

Setter for the pointer events.

Params:

Name Type Default Description
value boolean
false
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

draw

Draw legend.

Returns:

anychart.standalones.Legend - Self instance for method chaining.

Try it:

enabled

Getter for the current element state (enabled or disabled).

Returns:

boolean - The current element state.

Try it:

Setter for the element enabled state.

Params:

Name Type Default Description
value boolean
true
Value to set.

Returns:

anychart.core.VisualBase - Self instance for method chaining.
Example.
if (!element.enabled())
   element.enabled(true);

Try it:

fontColor

Getter for the text font color.

Returns:

string - The current font color.

Try it:

Setter for the text font color.
https://www.w3schools.com/html/html_colors.asp

Params:

Name Type Default Description
value string
"#7c868e"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

fontDecoration

Getter for the text font decoration.

Returns:

anychart.graphics.vector.Text.Decoration string - The current font decoration.

Try it:

Setter for the text font decoration.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.Decoration | string
"none"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

fontFamily

Getter for the current font family.

Returns:

string - The current font family.

Try it:

Setter for font family.

Params:

Name Type Default Description
value string
"Verdana", Helvetica, Arial, sans-serif
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

fontOpacity

Getter for the text font opacity.

Returns:

number - The current font opacity.

Try it:

Setter for the text font opacity. Double value from 0 to 1.

Params:

Name Type Default Description
value number
1
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

fontSize

Getter for the current text font size.

Returns:

string number - Current font size.

Try it:

Setter for text font size.

Params:

Name Type Default Description
value string | number
16
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

fontStyle

Getter for the text font style.

Returns:

anychart.graphics.vector.Text.FontStyle string - The current font style.

Try it:

Setter for the text font style.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.FontStyle | string
"normal"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

fontVariant

Getter for the text font variant.

Returns:

anychart.graphics.vector.Text.FontVariant string - The current font variant.

Try it:

Setter for the text font variant.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.FontVariant | string
"normal"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

fontWeight

Getter for the text font weight.

Returns:

string number - The current font weight.

Try it:

Setter for the text font weight.
https://www.w3schools.com/cssref/pr_font_weight.asp

Params:

Name Type Default Description
value string | number
"normal"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

getRemainingBounds

Getter for remain bounds after legend.

Returns:

anychart.math.Rect - Bounds that remain after legend.

Try it:

hAlign

Getter for the text horizontal align.

Returns:

anychart.graphics.vector.Text.HAlign string - The current text horizontal align.

Try it:

Setter for the text horizontal align.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.HAlign | string
"start"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

height

Getter for legend height.

Returns:

number string null - Current height.

Try it:

Setter for legend height.

Params:

Name Type Default Description
value number | string | null
null
Value to set.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

hoverCursor

Getter for hover cursor settings.

Returns:

anychart.enums.Cursor string - Hover cursor settings.

Try it:

Setter for hover cursor settings.

Params:

Name Type Default Description
value anychart.enums.Cursor | string
"pointer"
Hover cursor setting.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

iconSize

Getter for icon size.

Returns:

number - Icon size setting.

Try it:

Setter for icon size.

Params:

Name Type Description
value number | string Icon size setting.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

iconTextSpacing

Getter for spacing between icon and text in a legend item.

Returns:

number - Spacing settings.

Try it:

Setter for spacing between icon and text in a legend item.

Params:

Name Type Default Description
value string | number
5
Spacing settings.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

inverted

Getter for inverted settings.

Returns:

boolean - Inverted settings.

Try it:

Setter for inverted settings.

Params:

Name Type Default Description
value boolean
false
Whether item list should be inverted or not.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

items

Getter for custom items.

Returns:

Array.<anychart.core.ui.Legend.LegendItemProvider> - Current custom item.
Setter for custom items.

Params:

Name Type Default Description
value Array.<anychart.core.ui.Legend.LegendItemProvider>
null
Items.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

itemsFormatter

Getter for items formatter.

Returns:

function - Formatter function.
Setter for items formatter.

Params:

Name Type Default Description
value function
function (a){return a}
Formatter function.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

itemsLayout

Getter for items layout.

Returns:

anychart.enums.LegendLayout string - Current items layout.

Try it:

Setter for items layout.

Params:

Name Type Default Description
value string | anychart.enums.LegendLayout
"horizontal"
Layout type for legend items.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

itemsSource

Getter for items source.

Returns:

anychart.core.SeparateChart Array.<anychart.core.SeparateChart> - Items source.
Setter for items source.

Params:

Name Type Description
value anychart.core.SeparateChart | Array.<anychart.core.SeparateChart> Items source.

Returns:

anychart.standalones.Legend - Self instance for method chaining.

Try it:

itemsSourceMode

Getter for items source mode.

Returns:

string anychart.enums.LegendItemsSourceMode - Items source mode.

Try it:

Setter for items source mode.

Params:

Name Type Default Description
value string | anychart.enums.LegendItemsSourceMode
"default"
Items source mode.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

itemsSpacing

Getter for items spacing settings.

Returns:

string number - Items spacing settings.

Try it:

Setter for items spacing settings.

Params:

Name Type Default Description
value string | number
15
Value to set.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

letterSpacing

Getter for the text letter spacing.

Returns:

string number - The current letter spacing.

Try it:

Params:

Name Type Default Description
value string | number
"normal"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

lineHeight

Getter for the text line height.

Returns:

string number - The current text line height.

Try it:

Params:

Name Type Default Description
value string | number
"normal"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

listen

Adds an event listener to an implementing object.

Params:

Name Type Description
type string The event type id.
listener function Callback method. Function that looks like function(event){ // event.actualTarget - actual event target // event.currentTarget - current event target // event.iterator - event iterator // event.originalEvent - original event // event.point - event point // event.pointIndex - event point index }.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope Object Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

Try it:

listenOnce

Adds an event listener to an implementing object.

Params:

Name Type Description
type string The event type id.
listener function Callback method.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope Object Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

Try it:

margin

Setter for legend margin in pixels using a single value.

Params:

Name Type Default Description
value Array.<(number|string)> | Object | number | string
{top: 4, right: 4, bottom: 4, left: 4}
Space value, object or array.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

Setter for legend margin in pixels using a single simple values.

Params:

Name Type Default Description
value1 string | number
4
Top or top-bottom space.
value2 string | number
4
Right or right-left space.
value3 string | number
4
Bottom space.
value4 string | number
4
Left space.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

padding

Setter for legend padding in pixels using a single value.

Params:

Name Type Default Description
value Array.<(number|string)> | Object | number | string
{top: 7, right: 7, bottom: 7, left: 7}
Space value, object or array.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

Setter for legend padding setting in pixels using a several value.

Params:

Name Type Default Description
value1 string | number
7
Top or top-bottom space.
value2 string | number
7
Right or right-left space.
value3 string | number
7
Bottom space.
value4 string | number
7
Left space.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

paginator

Getter for paginator setting.

Returns:

anychart.core.ui.Paginator - Current settings.
Setter for paginator setting.

Params:

Name Type Default Description
value Object | boolean | null
true
Value to set.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

parentBounds

Getter for bounds. As a getter falls back to stage bounds.

Returns:

anychart.math.Rect - Current bounds.
Setter for bounds using single value.

Params:

Name Type Description
value anychart.math.Rect | Object | null Value to set

Returns:

anychart.standalones.Legend - Self instance for method chaining.

Try it:

Setter for bounds using several value.

Params:

Name Type Description
left number Left space.
top number Top space.
width number A width for a legend.
height number A height for a legend.

Returns:

anychart.standalones.Legend - Self instance for method chaining.

Try it:

position

Getter for legend position setting.

Returns:

anychart.enums.Orientation string - Legend position.

Try it:

Setter for legend position setting.

Params:

Name Type Default Description
value anychart.enums.Orientation | string
"bottom"
Legend position.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

print

Prints all elements on related stage.

Params:

Name Type Default Description
paperSizeOrOptions anychart.graphics.vector.PaperSize | Object
Paper size or object with options.
landscape boolean
false
Flag of landscape.

Try it:

removeAllListeners

Removes all listeners from an object. You can also optionally remove listeners of some particular type.

Params:

Name Type Description
type string Type of event to remove, default is to remove all types.

Returns:

number - Number of listeners removed.

Try it:

selectable

Getter for the text selectable option.

Returns:

boolean - The current text selectable option.

Try it:

Setter for the text selectable.

Params:

Name Type Default Description
value boolean
false
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

textDirection

Getter for the text direction.

Returns:

anychart.graphics.vector.Text.Direction string - Current text direction.

Try it:

Setter for the text direction.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.Direction | string
"ltr"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

textIndent

Getter for the text indent.

Returns:

number - The current text indent.

Try it:

Setter for the text indent.

Params:

Name Type Default Description
value number
0
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

textOverflow

Getter for the text overflow settings.

Returns:

anychart.graphics.vector.Text.TextOverflow string - The current text overflow settings.

Try it:

Setter for the text overflow settings.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.TextOverflow | string
""
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

textSettings

Getter for the full text appearance settings.

Returns:

Object - A copy of settings object.

Try it:

Getter for all text appearance settings.

Params:

Name Type Description
name string Setting name.

Returns:

string number boolean undefined - Value of the setting.

Try it:

Setter for text appearance settings.

Params:

Name Type Description
objectWithSettings Object Settings object. Complete object looks like this: { "fontSize": smth, "fontFamily": smth, "fontColor": smth, "fontOpacity": smth, "fontDecoration": smth, "fontStyle": smth, "fontVariant": smth, "fontWeight": smth, "letterSpacing": smth, "textDirection": smth, "lineHeight": smth, "textIndent": smth, "vAlign": smth, "hAlign": smth, "textWrap": smth, "textOverflow": smth, "selectable": smth, "useHtml": smth }.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

Setter for the text appearance settings.

Params:

Name Type Description
name string Setting name.
value string | number | boolean | function Settings value.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

textWrap

Getter for the text wrap settings.

Returns:

anychart.graphics.vector.Text.TextWrap string - The current text wrap settings.

Try it:

Setter for the text wrap settings.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.TextWrap | string
"byLetter"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

title

Getter for legend title.

Returns:

anychart.core.ui.Title - Title settings.
Setter for legend title.

Params:

Name Type Default Description
value null | boolean | Object | string
false
Value to set.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

titleFormat

Getter for the legend title format function.

Returns:

string function - Token or function to format title.

Try it:

Setter for the legend title format function. If set, formats title. Currently supported in Stock only. Learn more about using titleFormat() method.

Params:

Name Type Description
value string | function Token or function to format title.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

titleSeparator

Getter for title separator setting.

Returns:

anychart.core.ui.Separator - Current settings.
Setter for title separator setting.

Params:

Name Type Default Description
value Object | boolean | null
false
Value to set.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

tooltip

Getter for legend tooltip.

Returns:

anychart.core.ui.Tooltip - Tooltip instance.

Try it:

Setter for legend tooltip.

Params:

Name Type Default Description
value Object | boolean | null
true
Tooltip settings.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

unlisten

Removes a listener added using listen() or listenOnce() methods.

Params:

Name Type Description
type string The event type id.
listener function Callback method.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope Object Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.

Try it:

unlistenByKey

Removes an event listener which was added with listen() by the key returned by listen() or listenOnce().

Params:

Name Type Description
key Object The key returned by listen() or listenOnce().

Returns:

boolean - Whether any listener was removed.

Try it:

useHtml

Getter for the useHTML flag.

Returns:

boolean - The current value of useHTML flag.

Try it:

Setter for flag useHTML.

Params:

Name Type Default Description
value boolean
false
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

vAlign

Getter for the text vertical align.

Returns:

anychart.graphics.vector.Text.VAlign string - The current text vertical align.

Try it:

Setter for the text vertical align.

Params:

Name Type Default Description
value anychart.graphics.vector.Text.VAlign | string
"top"
Value to set.

Returns:

anychart.core.Text - Self instance for method chaining.

Try it:

width

Getter for legend width.

Returns:

number string null - Current width.

Try it:

Setter for legend width.

Params:

Name Type Default Description
value number | string | null
null
Value to set.

Returns:

anychart.core.ui.Legend - Self instance for method chaining.

Try it:

zIndex

Getter for the current Z-index of the element.

Returns:

number - The current zIndex.

Try it:

Setter for the Z-index of the element.

Params:

Name Type Default Description
value number
0
Value to set.

Returns:

anychart.core.VisualBase - Self instance for method chaining.

Try it: