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

class anychart.elements.Label Improve this Doc

Extends: anychart.elements.Text

Label element class.
Label can be a part of another element (such as chart, legend, axis, etc) or it can be used independently.
Label has a background and a large number of positioning options:

Try it:

Methods Overview

Miscellaneous
adjustFontSize()Getter for current adjust font settings.
anchor()Getter for label anchor settings.
background()Getter for the Label background settings.
draw()Render label content.
height()Getter for label height.
maxFontSize()Gets font size setting for adjust text to.
minFontSize()Gets font size setting for adjust text from.
offsetX()Getter for current label offsetX settings.
offsetY()Getter for current label offsetY settings.
padding()Getter for current label padding.
parentBounds()Returns positioning bounds.
position()Getter for current label position settings.
rotation()Gets or sets label rotation settings.
text()Gets text content for a current label.
width()Getter for label width.

Methods Description

adjustFontSize

Returns an array of two elements [isAdjustByWidth, isAdjustByHeight].
   [false, false] - do not adjust (adjust is off )
   [true, false] - adjust width
   [false, true] - adjust height
   [true, true] - adjust the first suitable value.

Returns:

Array.<boolean, boolean> - adjustFontSite setting or self for method chaining.
Sets adjusting settings.
Minimal and maximal font sizes can be configured using: anychart.elements.Label#minFontSize and anychart.elements.Label#maxFontSize.
Note: Works only when anychart.elements.Label#width and anychart.elements.Label#height are set.
Note: anychart.elements.Label#fontSize does not work when adjusting is enabled.

Params:

Name Type Description
bothOrByWidth boolean | Array.<boolean, boolean> 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.elements.Label - anychart.elements.Label instance for method chaining.

anchor

Getter for label anchor settings.

Returns:

anychart.enums.Anchor - Current label anchor settings.
Setter for label anchor settings.
Note: merges label positioning point (anychart.elements.Label#position) with an anchor.

Params:

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

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

background

Getter for the Label background settings.
Note: By default background is disabled. Set enabled(true) to start working with it.

Returns:

anychart.elements.Background - Returns the background settings.
Setter for Label background settings.

Params:

Name Type Description
value anychart.elements.Background Value to set.

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

draw

Render label content.

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

height

Getter for label height.

Returns:

number string null - Current label width.
Setter for label height.
Note: if null is passed, height is calculated automatically.

Params:

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

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

maxFontSize

Gets font size setting for adjust text to.

Returns:

number - Current value.
Sets font size setting for adjust text to.
Note: works only when adjusting is enabled. Look anychart.elements.Label#adjustFontSize.

Params:

Name Type Description
value number | string Value to set.

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

minFontSize

Gets font size setting for adjust text from.

Returns:

number - Current value.
Sets font size setting for adjust text from.
Note: works only when adjusting is enabled. Look anychart.elements.Label#adjustFontSize.

Params:

Name Type Description
value number | string Value to set.

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

offsetX

Getter for current label offsetX settings.

Returns:

number string - Label offsetX value.
Setter for label offsetX settings.

Params:

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

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

offsetY

Getter for current label offsetY settings.

Returns:

number string - Label offsetY value.
Setter for label offsetY settings. See illustration in anychart.elements.Label#offsetX.

Params:

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

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

padding

Getter for current label padding.
See how paddings work at anychart.Chart#padding.

Returns:

anychart.utils.Padding - Current label padding.
Setter for label padding in pixels by one value.

Params:

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

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.
Setter for label padding in pixels.

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.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

parentBounds

Returns positioning bounds.

Returns:

anychart.math.Rect - Current parent bounds.
Sets positioning bounds.
If width, height or offsets are set in percents - these are percents of these bounds.

Params:

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

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

position

Getter for current label position settings.

Returns:

anychart.enums.Position - Current label position settings.
Setter for label position settings.
Note: works only if anychart.elements.Label#container or anychart.elements.Label#parentBounds are explicitly set.

Params:

Name Type Default Description
value anychart.enums.Position | string
anychart.enums.Position.LEFT_TOP
Value to set.

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

rotation

Gets or sets label rotation settings.

Params:

Name Type Description
value number Label rotation settings.

Returns:

number anychart.elements.Label - Label rotation settings or itself for method chaining.

text

Gets text content for a current label.

Returns:

string - Current text content of a label.
Sets text content for a label.

Params:

Name Type Default Description
value string
'Label text'
Value to set.

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it:

width

Getter for label width.

Returns:

number string null - Current label width.
Setter for label width.
Note: if null is passed, width is calculated automatically.

Params:

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

Returns:

anychart.elements.Label - anychart.elements.Label instance for method chaining.

Try it: