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

class anychart.core.ui.Label Improve this Doc

Extends: anychart.core.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:

Methods Overview

Miscellaneous
adjustFontSize()Getter for current adjust font settings.
anchor()Getter for label anchor settings.
background()Getter for the Label background settings.
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.
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.core.ui.Label#minFontSize and anychart.core.ui.Label#maxFontSize.
Note: Works only when anychart.core.ui.Label#width and anychart.core.ui.Label#height are set.
Note: anychart.core.ui.Label#fontSize does not work when adjusting is enabled.

Params:

Name Type Description
bothOrByWidth boolean | Array.<boolean, boolean> | Object 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.ui.Label - Self instance for method chaining.
Example
label.adjustFontSize(false);
// the same
label.adjustFontSize(false, false);
// the same
label.adjustFontSize([false, false]);

Try it:

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.core.ui.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.core.ui.Label - Self 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.core.ui.Background - Returns the background settings.
Setter for Label background settings.

Params:

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

Returns:

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

Try it:

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.core.ui.Label - Self 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.core.ui.Label#adjustFontSize.

Params:

Name Type Description
value number | string Value to set.

Returns:

anychart.core.ui.Label - Self 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.core.ui.Label#adjustFontSize.

Params:

Name Type Description
value number | string Value to set.

Returns:

anychart.core.ui.Label - Self 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.core.ui.Label - Self 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.core.ui.Label#offsetX.

Params:

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

Returns:

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

Try it:

padding

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

Returns:

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

Params:

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

Returns:

anychart.core.ui.Label - Self 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.core.ui.Label - Self instance for method chaining.
Example
// 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);

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.core.ui.Label#container or anychart.core.ui.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.core.ui.Label - Self instance for method chaining.

rotation

Gets or sets label rotation settings.

Params:

Name Type Description
value number Label rotation settings.

Returns:

number anychart.core.ui.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.core.ui.Label - Self 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.core.ui.Label - Self instance for method chaining.

Try it: