AnyChart
API Reference
Still have questions?
Contact support
Top

class anychart.core.ui.Legend Improve this Doc

Extends: anychart.core.Text

Legend element.

Methods Overview

Specific settings
iconSize()Icon size.
inverted()Inverted settings.
items()Custom items.
itemsFormat()Items text formatter.
itemsFormatter()Items formatter.
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.
useHtml()Text useHtml settings.
wordBreak()Word break mode.
wordWrap()Word-wrap mode.
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.
textShadow()Text shadow settings.
vAlign()Text vertical align settings.
Coloring
background()Background settings.
Events
disablePointerEvents()Pointer events settings.
Interactivity
drag()Enable/disable drag for a legend.
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.
getPixelBounds()Returns pixel bounds of the legend.
getRemainingBounds()Getter for remain bounds after legend.
height()Height settings.
iconTextSpacing()Spacing between icon and text.
itemsHAlign()Items layout horizontal align.
itemsLayout()Items layout settings.
itemsSpacing()Items spacing settings.
margin()Margin settings.
maxHeight()Maximum height.
maxWidth()Maximum width.
padding()Padding settings.
position()Position settings.
positionMode()Position mode settings.
width()Width settings.
zIndex()Z-index of the element.
Text Settings
textSettings()Text settings.

Methods Description

align

Getter for legend align settings.

Returns:

anychart.enums.Align | string - Legend align.
Setter for legend align settings.

Params:

NameTypeDefaultDescription
alignanychart.enums.Align | string
'center'
Align to set.

Returns:

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

background

Getter for the legend background.

Returns:

anychart.core.ui.Background - Background settings.
See listing
var background = legend.background();
Setter for the legend background.

Params:

NameTypeDefaultDescription
settingsstring | Object | null | boolean
true
Background settings.

Returns:

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

disablePointerEvents

Getter for the pointer events.

Returns:

boolean - Flag of the state.
Setter for the pointer events.

Params:

NameTypeDefaultDescription
enabledboolean
false
Enabled state to set.

Returns:

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

drag

Gets a value for dragging.

Returns:

boolean - The dragging value.
See listing.
var drag = legend.drag();
Allows to use drag for legend.

Params:

NameTypeDescription
enabledbooleanAllows dragging of the legend.

Returns:

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

enabled

Getter for the legend state (enabled or disabled).

Returns:

boolean - Element state.
Setter for the legend enabled state.

Params:

NameTypeDefaultDescription
enabledboolean
true
Enabled state to set.

Returns:

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

fontColor

Getter for the text font color.

Returns:

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

Params:

NameTypeDefaultDescription
colorstring
'#7c868e'
Value to set.

Returns:

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

fontDecoration

Getter for the text font decoration.

Returns:

anychart.graphics.vector.Text.Decoration | string - Font decoration.
Setter for the text font decoration.

Params:

NameTypeDefaultDescription
valueanychart.graphics.vector.Text.Decoration | string
'none'
Font decoration to set.

Returns:

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

fontFamily

Getter for the font family.

Returns:

string - Font family.
Setter for the font family.

Params:

NameTypeDefaultDescription
familystring
'Verdana', Helvetica, Arial, sans-serif
Font family to set.

Returns:

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

fontOpacity

Getter for the text font opacity.

Returns:

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

Params:

NameTypeDefaultDescription
opacitynumber
1
Value to set.

Returns:

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

fontSize

Getter for the legend font size.

Returns:

string | number - Font size.
Setter for the legend font size.

Params:

NameTypeDefaultDescription
sizestring | number
12
Font size to set.

Returns:

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

fontStyle

Getter for the text font style.

Returns:

anychart.graphics.vector.Text.FontStyle | string - Font style.
Setter for the text font style.

Params:

NameTypeDefaultDescription
styleanychart.graphics.vector.Text.FontStyle | string
'normal'
Font style to set.

Returns:

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

fontVariant

Getter for the text font variant.

Returns:

anychart.graphics.vector.Text.FontVariant | string - Font variant.
Setter for the text font variant.

Params:

NameTypeDefaultDescription
valueanychart.graphics.vector.Text.FontVariant | string
'normal'
Font variant to set.

Returns:

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

fontWeight

Getter for the text font weight.

Returns:

string | number - Font weight.

Params:

NameTypeDefaultDescription
weightstring | number
'normal'
Font weight to set.

Returns:

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

getPixelBounds

Returns pixel bounds of the legend.

Returns:

anychart.math.Rect - Pixel bounds of the legend.

getRemainingBounds

Getter for remain bounds after legend.

Returns:

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

hAlign

Getter for the text horizontal align.

Returns:

anychart.graphics.vector.Text.HAlign | string - Text horizontal align.
Setter for the text horizontal align.

Params:

NameTypeDefaultDescription
alignanychart.graphics.vector.Text.HAlign | string
'start'
Value to set.

Returns:

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

height

Getter for the legend height.

Returns:

number | string | null - Legend height.
Setter for the legend height.

Params:

NameTypeDefaultDescription
heightnumber | string | null
null
Legend height to set.

Returns:

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

hoverCursor

Getter for hover cursor settings.

Returns:

anychart.enums.Cursor | string - Hover cursor settings.
Setter for hover cursor settings.

Params:

NameTypeDefaultDescription
cursorTypranychart.enums.Cursor | string
'pointer'
Hover cursor setting.

Returns:

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

iconSize

Getter for the icon size.

Returns:

number - Icon size.
Setter for the icon size.

Params:

NameTypeDescription
sizenumber | stringIcon size setting.

Returns:

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

iconTextSpacing

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

Returns:

number - Spacing settings.
Setter for spacing between icon and text in a legend item.

Params:

NameTypeDefaultDescription
spacingstring | number
5
Spacing settings.

Returns:

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

inverted

Getter for inverted settings.

Returns:

boolean - Inverted settings.
Setter for inverted settings.

Params:

NameTypeDefaultDescription
enabledboolean
false
Whether item list should be inverted or not.

Returns:

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

items

Getter for custom items.

Returns:

Array.<anychart.core.ui.Legend.LegendItemProvider> - Custom item.
See listing
var items = legend.items();
Setter for custom items.

Params:

NameTypeDefaultDescription
itemsListArray.<anychart.core.ui.Legend.LegendItemProvider>
null
Items array to set.

Returns:

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

itemsFormat

Getter for items text formatter.

Returns:

function - Items text formatter function.
See listing
var itemsFormat = legend.itemsFormat();
Setter for items text formatter.
Learn more about using itemsFormat() method.

Params:

NameTypeDescription
formatfunction(value:Object):string | stringItems text formatter function.

Returns:

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

itemsFormatter

Getter for items formatter.

Returns:

function(items:Array.<anychart.core.ui.Legend.LegendItemProvider>):Array.<anychart.core.ui.Legend.LegendItemProvider> - Formatter function.
See listing
var itemsFormatter = legend.itemsFormatter();
Setter for items formatter.

Params:

NameTypeDefaultDescription
formatterFunctionfunction(items:Array.<anychart.core.ui.Legend.LegendItemProvider>):Array.<anychart.core.ui.Legend.LegendItemProvider>
function (a){return a}
Formatter function.

Returns:

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

itemsHAlign

Getter for items horizontal align.

Returns:

anychart.enums.HAlign | string - Items horizontal align.
Setter for items horizontal align. Aligns item by legend width. Works only if anychart.core.ui.Legend#itemsLayout is 'horizontal'.

Params:

NameTypeDefaultDescription
hAlignanychart.enums.HAlign | string
'left'
Legend items horizontal align.

Returns:

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

itemsLayout

Getter for items layout.

Returns:

anychart.enums.LegendLayout | string - Items layout.
Setter for items layout.

Params:

NameTypeDefaultDescription
layoutanychart.enums.LegendLayout | string
'horizontal'
Layout type for legend items.

Returns:

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

itemsSourceMode

Getter for items source mode.

Returns:

anychart.enums.LegendItemsSourceMode | string - Items source mode.
Setter for items source mode.

Params:

NameTypeDefaultDescription
modeanychart.enums.LegendItemsSourceMode | string
'default'
Items source mode.

Returns:

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

itemsSpacing

Getter for items spacing settings.

Returns:

string | number - Items spacing settings.
Setter for items spacing settings.

Params:

NameTypeDefaultDescription
spacingstring | number
15
Value to set.

Returns:

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

letterSpacing

Getter for the text letter spacing.

Returns:

string | number - Letter spacing.

Params:

NameTypeDefaultDescription
spacingstring | number
'normal'
Value to set.

Returns:

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

lineHeight

Getter for the text line height.

Returns:

string | number - Text line height.

Params:

NameTypeDefaultDescription
heightstring | number
'normal'
Value to set.

Returns:

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

margin

Setter for the legend margin in pixels using a single value.

Params:

NameTypeDefaultDescription
marginArray.<(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.
Setter for the legend margin in pixels using a single simple values.

Params:

NameTypeDefaultDescription
value1string | number
4
Top or top-bottom space.
value2string | number
4
Right or right-left space.
value3string | number
4
Bottom space.
value4string | number
4
Left space.

Returns:

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

maxHeight

Getter for the maximum height.

Returns:

number | string | null - The maximum height.
See listing.
var maxHeight = legend.maxHeight();
Setter for the maximum height.

Params:

NameTypeDefaultDescription
heightnumber | string
null
Maximum height to set.

Returns:

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

maxWidth

Getter for the maximum width.

Returns:

number | string | null - The maximum width.
See listing.
var maxWidth = legend.maxWidth();
Setter for the maximum width.

Params:

NameTypeDefaultDescription
widthnumber | string | null
null
Maximum width to set.

Returns:

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

padding

Setter for the legend padding in pixels using a single value.

Params:

NameTypeDefaultDescription
paddingArray.<(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.
Setter for the legend padding setting in pixels using a several values.

Params:

NameTypeDefaultDescription
value1string | number
7
Top or top-bottom space.
value2string | number
7
Right or right-left space.
value3string | number
7
Bottom space.
value4string | number
7
Left space.

Returns:

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

paginator

Getter for paginator settings.

Returns:

anychart.core.ui.Paginator - Paginator settings.
See listing
var paginator = legend.paginator();
Setter for paginator settings.

Params:

NameTypeDefaultDescription
settingsObject | boolean | null
true
Paginator settings to set.

Returns:

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

position

Getter for legend position settings.

Returns:

anychart.enums.Orientation | string - Legend position.
Setter for legend position setting.

Params:

NameTypeDefaultDescription
positionanychart.enums.Orientation | string
'bottom'
Legend position to set.

Returns:

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

positionMode

Getter for the position mode.

Returns:

anychart.enums.LegendPositionMode | string - Legend position mode.
See listing.
var positionMode = legend.positionMode();
Setter for the position mode.

Params:

NameTypeDescription
modeanychart.enums.LegendPositionMode | stringLegend position mode.

Returns:

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

selectable

Getter for the text selectable option.

Returns:

boolean - The text selectable option.
Setter for the text selectable.

Params:

NameTypeDefaultDescription
enabledboolean
false
Enabled state to set.

Returns:

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

textDirection

Getter for the text direction.

Returns:

anychart.graphics.vector.Text.Direction | string - Text direction.
Setter for the text direction.

Params:

NameTypeDefaultDescription
directionanychart.graphics.vector.Text.Direction | string
'ltr'
Text direction to set.

Returns:

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

textIndent

Getter for the text indent.

Returns:

number - Text indent.
Setter for the text indent.

Params:

NameTypeDefaultDescription
indentnumber
0
Text indent to set.

Returns:

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

textOverflow

Getter for the text overflow settings.

Returns:

anychart.graphics.vector.Text.TextOverflow | string - Text overflow settings.
See listing
var title = chart.title();
var textOverflow = title.textOverflow();
Setter for the text overflow settings.

Params:

NameTypeDefaultDescription
valueanychart.graphics.vector.Text.TextOverflow | string
""
Text overflow settings to set.

Returns:

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

textSettings

Getter for the full text appearance settings.

Returns:

Object - A copy of settings object.
Getter for all text appearance settings.

Params:

NameTypeDescription
namestringSetting name.

Returns:

string | number | boolean | undefined - Value of settings.
Setter for text appearance settings.

Params:

NameTypeDescription
objectWithSettingsObjectSettings 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,
     'wordWrap': smth,
     'wordBreak': smth,
     'textOverflow': smth,
     'selectable': smth,
     'useHtml': smth
     'textShadow':smth
   }

Returns:

anychart.core.ui.Legend - Self instance for method chaining.
Setter for the text appearance settings.

Params:

NameTypeDescription
namestringSetting name.
settingsstring | number | boolean | functionText settings.

Returns:

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

textShadow

Getter for the text shadow.

Returns:

string - String representation of text shadow.
Setter for the text shadow.

Params:

NameTypeDefaultDescription
textShadowanychart.graphics.vector.TextShadow | string
'none'
Text shadow to set.

Returns:

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

title

Getter for the legend title.

Returns:

anychart.core.ui.Title - Title settings.
See listing
var title = legend.title();
Setter for the legend title.

Params:

NameTypeDefaultDescription
settingsnull | boolean | Object | string
false
Title settings 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.
Setter for the legend title format function. If set, formats title. Currently supported in Stock only. Learn more about using titleFormat() method.

Params:

NameTypeDescription
formatstring | functionToken or function to format title.

Returns:

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

titleSeparator

Getter for title separator settings.

Returns:

anychart.core.ui.Separator - Title separator settings.
See listing
var titleSeparator = legend.titleSeparator();
Setter for title separator settings.

Params:

NameTypeDefaultDescription
settingsObject | boolean | null
false
Title separator settings to set.

Returns:

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

tooltip

Getter for the legend tooltip.

Returns:

anychart.core.ui.Tooltip - Tooltip instance.
Setter for legend tooltip.

Params:

NameTypeDefaultDescription
settingsObject | boolean | null
true
Tooltip settings to set.

Returns:

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

useHtml

Getter for the useHTML flag.

Returns:

boolean - Value of useHTML flag.
Setter for flag useHTML.

Params:

NameTypeDefaultDescription
enabledboolean
false
Enabled state to set.

Returns:

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

vAlign

Getter for the text vertical align.

Returns:

anychart.graphics.vector.Text.VAlign | string - Text vertical align.
Setter for the text vertical align.

Params:

NameTypeDefaultDescription
alignanychart.graphics.vector.Text.VAlign | string
'top'
Value to set.

Returns:

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

width

Getter for the legend width.

Returns:

number | string | null - Legend width.
Setter for the legend width.

Params:

NameTypeDefaultDescription
widthnumber | string | null
null
Legend width to set.

Returns:

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

wordBreak

Getter for the word-break mode.

Returns:

anychart.enums.WordBreak | string - Word-break mode.
Setter for the word-break mode.

Params:

NameTypeDefaultDescription
modeanychart.enums.WordBreak | string
"normal"
Word-break mode to set.

Returns:

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

wordWrap

Getter for the word-wrap mode.

Returns:

anychart.enums.WordWrap | string - Word-wrap mode.
Setter for the word-wrap mode.

Params:

NameTypeDefaultDescription
modeanychart.enums.WordWrap | string
'normal'
Word-wrap mode to set.

Returns:

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

zIndex

Getter for the Z-index of the element.

Returns:

number - Z-index.
Setter for the Z-index of the element.

Params:

NameTypeDefaultDescription
zIndexnumber
0
Value to set.

Returns:

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