AnyChart
API Reference
Still have questions?
Contact support
Top

class anychart.core.annotations.Label Improve this Doc

Extends: anychart.core.annotations.Base

Label annotation.

Methods Overview

Specific settings
getPlot()Returns the plot on which the annotation is drawn.
getType()Returns annotation type.
markers()Markers settings.
text()Label text.
Axes and Scales
xScale()X-scale settings
yScale()Y-scale settings
Charts
getChart()Returns the chart on which the annotation is drawn.
Coloring
background()Background settings.
color()Color settings.
Content Text Settings
adjustFontSize()Adjusting settings.
disablePointerEvents()Pointer events 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.
fontVariant()Font variant settings.
fontWeight()Font weight settings.
hAlign()Text horizontal align settings.
letterSpacing()Text letter spacing settings.
lineHeight()Line height settings.
maxFontSize()Maximum font size setting.
minFontSize()Minimum font size settings.
textDirection()Text direction settings.
textIndent()Text indent settings.
textOverflow()Text overflow settings.
useHtml()Text useHtml settings.
vAlign()Text vertical align settings.
wordBreak()Word break mode.
wordWrap()Word-wrap mode.
Events
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
allowEdit()Interactivity settings.
enabled()Element state (enabled or disabled).
hovered()Hovered state settings.
normal()Normal state settings.
selectable()Text selectable option.
selected()Selected state settings.
Size and Position
anchor()Anchor settings.
bottom()Bottom bound settings.
bounds()Bounds settings.
getPixelBounds()Returns pixel bounds.
height()Height settings.
hoverGap()Hover gap settings.
left()Left bound settings.
maxHeight()Maximum height.
maxWidth()Maximum width.
minHeight()Minimum height.
minWidth()Minimum width.
offsetX()Offset by X.
offsetY()Offset by Y.
padding()Padding settings.
right()Right bound settings.
top()Top bound settings.
valueAnchor()Value anchor settings
width()Width settings.
xAnchor()X anchor settings
zIndex()Z-index of the element.

Methods Description

adjustFontSize

Getter for the adjust font settings.

Returns:

Object - AdjustFontSize settings.
Setter for the adjust font settings.

Params:

Name Type Default Description
bothOrByWidth Object | Array.<boolean> | boolean
{width: false, height: false}
If only one param is set, its value goes for another too (see source code).
byHeight boolean
Is font needs to be adjusted by height.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.
Example
label.adjustFontSize(false);
// the same
label.adjustFontSize(false, false);
// the same
label.adjustFontSize([false, false]);

allowEdit

Getter for an interactivity in the annotation.

Returns:

boolean - Interactivity settings.
See listing.
var currentAllowEdit = annotation.allowEdit();
Setter for an interactivity in the annotation.

Params:

Name Type Description
value * Whether to disable the interactivity in the annotation. If set to false, the interactivity is disabled in the annotation.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

anchor

Getter for anchor settings.

Returns:

anychart.enums.Anchor string - Anchor value.
See listing
var anchor = annotation.anchor();
Setter for anchor settings.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

background

Getter for the background.

Returns:

anychart.core.ui.Background - Background instance.

Try it:

Setter for the background.

Params:

Name Type Default Description
value string | Object | null | boolean
"#eee 0.5"
Background object to set.

Returns:

anychart.core.annotations.Label - Returns the background or itself for method chaining.

bottom

Getter for element bottom bound settings.

Returns:

number string undefined - Element's bottom bound setting.
Setter for element bottom bound settings.

Params:

Name Type Default Description
value number | string | null
null
Bottom bound settings for the element.

Returns:

anychart.core.VisualBaseWithBounds - Returns self for method chaining.

Try it:

bounds

Getter for element bounds settings.

Returns:

anychart.core.utils.Bounds - Bounds of the element.
Setter for bounds of the element using one parameter.

Params:

Name Type Description
value anychart.utils.RectObj | anychart.math.Rect | anychart.core.utils.Bounds Bounds of element.

Returns:

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

Try it:

Setter for element bounds settings.

Params:

Name Type Default Description
x number | string
null
X-coordinate.
y number | string
null
Y-coordinate.
width number | string
null
Width.
height number | string
null
Height.

Returns:

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

Try it:

color

Getter for the annotation color.

Returns:

string - The annotation color.
See listing.
var color = annotation.color();
Setter for the annotation color.

Params:

Name Type Description
value string Color as a string.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

disablePointerEvents

Getter for the pointer events settings.

Returns:

boolean - The pointer events settings.
See listing
var disablePointerEvents = annotation.disablePointerEvents();
Setter for the pointer events settings.

Params:

Name Type Default Description
value boolean
false
Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

enabled

Getter for the element state (enabled or disabled).

Returns:

boolean - 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 font color settings.

Returns:

string - Font color settings.
See listing
var fontColor = annotation.fontColor();
Setter for font color settings.

Params:

Name Type Description
value string Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

fontDecoration

Getter for the text font decoration.

Returns:

anychart.graphics.vector.Text.Decoration string - Font decoration.
See listing
var fontDecoration = annotation.fontDecoration();
Setter for the text font decoration.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

fontFamily

Getter for the font family.

Returns:

string - Font family.
See listing
var fontDecoration = annotation.fontFamily();
Setter for font family.

Params:

Name Type Description
value string Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

fontOpacity

Getter for the text font opacity.

Returns:

number - Font opacity.
See listing
var fontOpacity = annotation.fontOpacity();
Setter for the text font opacity.
Double value from 0 to 1.

Params:

Name Type Description
value number Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

fontSize

Getter for font size settings.

Returns:

number - Font size settings.
See listing
var fontSize = annotation.fontSize();
Setter for font size settings.

Params:

Name Type Description
value number | string Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

fontStyle

Getter for font style settings.

Returns:

anychart.graphics.vector.Text.FontStyle - Font style settings.
See listing
var fontStyle = annotation.fontStyle();
Setter for font style settings.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

fontVariant

Getter for font variant settings.

Returns:

anychart.graphics.vector.Text.FontVariant - Font variant settings.
See listing
var fontVariant = annotation.fontVariant();
Setter for font variant settings.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

fontWeight

Getter for font weight settings.

Returns:

string number - Font weight settings.
See listing
var fontWeight = annotation.fontWeight();
Setter for font weight settings.

Params:

Name Type Description
value string | number Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

getChart

Returns the chart on which the annotation is drawn.

Returns:

anychart.core.SeparateChart - Chart.

Try it:

getPixelBounds

Returns pixel bounds of the element due to parent bounds and self bounds settings.

Returns:

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

getPlot

Returns the plot on which the annotation is drawn.

Returns:

anychart.core.stock.Plot - Stock plot.

Try it:

getType

Returns annotation type.

Returns:

anychart.enums.AnnotationTypes string - Annotation type

Try it:

hAlign

Getter for text horizontal align settings.

Returns:

anychart.graphics.vector.Text.HAlign - Horizontal align settings.
See listing
var hAlign = annotation.hAlign();
Setter for the text horizontal align settings.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

height

Getter for element height settings.

Returns:

number string undefined - Element's height setting.
Setter for element height setting.

Params:

Name Type Default Description
value number | string | null
null
Height settings for the element.

Returns:

anychart.core.VisualBaseWithBounds - Returns self for method chaining.

Try it:

hoverGap

Getter for the hover gap.

Returns:

number - The hover gap value.
See listing.
var currentHoverGap = annotation.hoverGap();
Setter for the hover gap.
The contour size around annotation.

Params:

Name Type Description
value * Value to set.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

hovered

Getter for hovered state settings.

Returns:

anychart.core.StateSettings - Hovered state settings

Try it:

Setter for hovered state settings.

Params:

Name Type Description
value Object State settings to set.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

left

Getter for element left bound settings.

Returns:

number string undefined - Element's left bound setting.
Setter for element left bound settings.

Params:

Name Type Default Description
value number | string | null
null
Left bound setting for the element.

Returns:

anychart.core.VisualBaseWithBounds - Returns self for method chaining.

Try it:

letterSpacing

Getter for letter spacing settings.

Returns:

number - Letter spacing settings.
See listing
var letterSpacing = annotation.letterSpacing();
Setter for letter spacing settings.

Params:

Name Type Description
value number Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

lineHeight

Getter for the text line height.

Returns:

string number - Text line height.
See listing
var lineHeight = annotation.lineHeight();

Params:

Name Type Description
value string | number Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

listen

Adds an event listener to an implementing object.

Params:

Name Type Default 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
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
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 Default Description
type string
The event type id.
listener function
Callback method.
useCapture boolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScope Object
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

Try it:

markers

Getter for data markers.

Returns:

anychart.core.ui.MarkersFactory - Markers instance.

Try it:

Setter for data markers.

Params:

Name Type Default Description
value Object | boolean | null | string
false
Data markers settings.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

maxFontSize

Getter for the font size for adjust text to.

Returns:

number - Maximum font size.
Setter for the font size for adjust text to.

Params:

Name Type Description
value number | string Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

maxHeight

Getter for the maximum height.

Returns:

number string null - Element's maximum height.
Setter for the maximum height.

Params:

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

Returns:

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

Try it:

maxWidth

Getter for the maximum width.

Returns:

number string null - Element's maximum width.
Setter for the maximum width.

Params:

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

Returns:

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

Try it:

minFontSize

Getter for minimum font size settings for adjust text from.

Returns:

number - Minimum font size.
Setter for minimum font size settings for adjust text from.

Params:

Name Type Description
value number | string Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

minHeight

Getter for the minimum height.

Returns:

number string null - Element's minimum height.
Setter for the minimum height.

Params:

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

Returns:

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

Try it:

minWidth

Getter for the minimum width.

Returns:

number string null - Element's minimum width.
Setter for the minimum width.

Params:

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

Returns:

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

Try it:

normal

Getter for normal state settings.

Returns:

anychart.core.StateSettings - Normal state settings.

Try it:

Setter for normal state settings.

Params:

Name Type Description
value Object State settings to set.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

offsetX

Getter for offset by X.

Returns:

number string - Label offsetX value.
See listing
var offsetX = annotation.offsetX();
Setter for offset by X.

Arrows show offsets layout.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

offsetY

Getter for offset by Y.

Returns:

number string - Label offsetY value.
See listing
var offsetY = annotation.offsetY();
Setter for offset by Y. See illustration in anychart.core.annotations.Label#offsetX.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

padding

Setter for paddings in pixels using a single value.

Params:

Name Type Default Description
value null | Array.<(number|string)> | Object
5
Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.
Examples for paddings
// all paddings 15px
label.padding(15);
// all paddings 15px
label.padding('15px');
// top and bottom 5px ,right and left 15px
label.padding(anychart.utils.padding(5,15));

Try it:

Setter for paddings in pixels using several numbers.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.
Examples for paddings
// 1) top and bottom 10px, left and right 15px
label.padding(10, '15px');
// 2) top 10px, left and right 15px, bottom 5px
label.padding(10, '15px', 5);
// 3) top 10px, right 15px, bottom 5px, left 12px
label.padding(10, '15px', '5px', 12);

Try it:

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:

Getter for element right bound settings.

Returns:

number string undefined - Element's right bound setting.
Setter for element right bound setting.

Params:

Name Type Default Description
value number | string | null
null
Right bound setting for the element.

Returns:

anychart.core.VisualBaseWithBounds - Returns self for method chaining.

Try it:

selectable

Getter for the text selectable option.

Returns:

boolean - Text selectable option.
See listing
var selectable = annotation.selectable();
Setter for the text selectable.

Params:

Name Type Default Description
value boolean
false
Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

selected

Getter for selected state settings.

Returns:

anychart.core.StateSettings - Selected state settings

Try it:

Setter for selected state settings.

Params:

Name Type Description
value Object State settings to set.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

text

Getter for the text content for a label.

Returns:

string - Text content of a label.
See listing
var text = annotation.text();
Setter for text content for a label.

Params:

Name Type Description
value string Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

textDirection

Getter for the text direction.

Returns:

anychart.graphics.vector.Text.Direction string - Text direction.
See listing
var textDirection = annotation.textDirection();
Setter for the text direction.

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

textIndent

Getter for the text indent.

Returns:

number - Text indent.
See listing
var textIndent = annotation.textIndent();
Setter for the text indent.

Params:

Name Type Description
value number Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

textOverflow

Getter for the text overflow settings.

Returns:

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

Params:

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

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

top

Getter for element top bound settings.

Returns:

number string undefined - Element's top bound setting.
Setter for element top bound settings.

Params:

Name Type Default Description
value number | string | null
null
Top bound setting for the element.

Returns:

anychart.core.VisualBaseWithBounds - Returns self for method chaining.

Try it:

unlisten

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

Params:

Name Type Default Description
type string
The event type id.
listener function
Callback method.
useCapture boolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
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 - Value of useHTML flag.
See listing
var useHtml = annotation.useHtml();
Setter for the useHTML flag.

Params:

Name Type Default Description
value boolean
false
Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

vAlign

Getter for the text vertical align.

Returns:

anychart.graphics.vector.Text.VAlign string - Text vertical align.
See listing
var vAlign = annotation.vAlign();
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.annotations.Label - Self instance for method chaining.

Try it:

valueAnchor

Getter for the value anchor.

Returns:

* - The value anchor.
See listing.
var valueAnchor = annotation.valueAnchor();
Setter for the value anchor.

Params:

Name Type Description
value * Value anchor to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

width

Getter for element width settings.

Returns:

number string undefined - Element's width setting.
Setter for element width setting.

Params:

Name Type Default Description
value number | string | null
null
Width settings for the element.

Returns:

anychart.core.VisualBaseWithBounds - Returns self for method chaining.

Try it:

wordBreak

Getter for the word-break mode.

Returns:

anychart.enums.WordBreak string - Word-break mode.
See listing.
var wordBreak = annotation.wordBreak();
Setter for the word-break mode.

Params:

Name Type Default Description
value anychart.enums.WordBreak | string
"normal"
Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

wordWrap

Getter for the word-wrap mode.

Returns:

anychart.enums.WordWrap string - Word-wrap mode.
See listing.
var wordWrap = annotation.wordWrap();
Setter for the word-wrap mode.

Params:

Name Type Default Description
value anychart.enums.WordWrap | string
"normal"
Value to set.

Returns:

anychart.core.annotations.Label - Self instance for method chaining.

Try it:

xAnchor

Getter for the X anchor.

Returns:

* - The X anchor.
See listing.
var xAnchor = annotation.xAnchor();
Setter for the X anchor.

Params:

Name Type Description
value * X anchor to set.

Returns:

anychart.core.annotations.Line - Self instance for method chaining.

Try it:

xScale

Setter for the X-scale.

Params:

Name Type Default Description
value anychart.scales.Base | anychart.scales.StockScatterDateTime | Object | anychart.enums.ScaleTypes | string
anychart.scales.Linear
Value to set

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

yScale

Getter for the Y-scale.

Returns:

anychart.scales.Base - Default scale value.

Try it:

Setter for the Y-scale.

Params:

Name Type Default Description
value anychart.scales.Base | Object | anychart.enums.ScaleTypes | string
anychart.scales.Linear
Y-scale to set.

Returns:

anychart.core.annotations.Base - Self instance for method chaining.

Try it:

zIndex

Getter for the Z-index of the element.

Returns:

number - Z-index.

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: