AnyChart
API Reference
Still have questions?
Contact support
Top

class anychart.graphics.vector.Text Improve this Doc

Extends: anychart.graphics.vector.Element

Text class.
Do not invoke constructor directly. Use anychart.graphics.vector.Stage#text or anychart.graphics.vector.Layer#text to create layer or stage bound text.
Use anychart.graphics#text to create unbound text.
See also:
anychart.graphics.vector.Stage#text,
anychart.graphics.vector.Layer#text,
anychart.graphics#text

Methods Overview

Coloring
color()Color setting.
Events
listen()Adds an event listener.
listenOnce()Adds an event listener that is removed automatically after the listener fired once.
removeAllListeners()Removes all listeners from this listenable.
unlisten()Removes an event listener which was added with listen() or listenOnce().
Interactive
drag()Dragging setting.
Interactivity
visible()Visibility flag
Size and Position
appendTransformationMatrix()Combines the transformation with the given transformation matrix.
getAbsoluteBounds()Gets element bounds in absolute coordinates (root element coordinate system).
getAbsoluteHeight()Returns height within root bounds.
getAbsoluteWidth()Returns width within root bounds.
getAbsoluteX()Returns an absolute X (root element coordinate system).
getAbsoluteY()Returns an absolute Y (root element coordinate system).
getBounds()Returns the bounds.
getHeight()Returns the height.
getRotationAngle()Returns the rotation angle in degrees.
getTransformationMatrix()Returns the transformation matrix.
getWidth()Returns the width.
getX()Returns X in the coordinate system of the parent.
getY()Returns Y in the coordinate system of the parent.
height()Height setting.
rotate()Rotates a shape around the given rotation point.
rotateByAnchor()Rotates a shape around the given anchor.
scale()Scales a shape. Scaling center is set in the coordinate system of the parent.
scaleByAnchor()Scales a shape by anchor. Scaling center is set as an anchor.
setPosition()Sets top left corner of a shape (transformation taken into account) in the coordinate system of the parent.
setRotation()Rotates a shape around the given point.
setRotationByAnchor()Rotates a shape around the given anchor.
setTransformationMatrix()Sets the transformation matrix.
translate()Moves a shape taking an account the transformation.
width()Width setting.
x()X coordinate setting.
y()Y coordinate setting.
zIndex()Z-index setting.
Miscellaneous
attr()Attribute setting
clip()Clipping setting.
cursor()Cursor type.
decoration()Text decoration setting.
desc()Description setting
direction()Text direction setting.
disablePointerEvents()Pointer events setting.
disableStrokeScaling()Vector effect property
dispose()Disposes element completely.
domElement()Returns DOM element if element is rendered.
fontFamily()Font family setting.
fontSize()Font size setting.
fontStyle()Font style setting.
fontVariant()Font variant setting.
fontWeight()Font weight setting.
getStage()Stage object (to which the given element is bound).
getTextHeight()Returns actual text height.
getTextWidth()Returns actual text width.
hAlign()Horizontal align setting.
hasParent()Whether parent element is set.
htmlText()HTML format.
id()Element identifier
letterSpacing()Letter spacing setting.
lineHeight()Line height setting.
opacity()Opacity setting.
parent()Parent layer.
path()Path element for the text.
remove()Current element removes itself from the parent layer.
selectable()Text selection setting.
style()Text style settings.
text()Text setting.
textIndent()Text indent setting.
textOverflow()Text overflow setting.
title()Title setting
vAlign()Vertical align setting.
wordBreak()Text word-break mode.
wordWrap()Text word-wrap mode.

Methods Description

appendTransformationMatrix

Combines the transformation with the given transformation matrix.

Params:

NameTypeDescription
m00numberScale X.
m10numberShear Y.
m01numberShear X.
m11numberScale Y.
m02numberTranslate X.
m12numberTranslate Y.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

attr

Getter for the attribute.

Params:

NameTypeDescription
keystringName of attribute.

Returns:

* - Attribute value.
Setter for the attribute.

Params:

NameTypeDescription
keystringName of attribute.
value*Value of attribute.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

clip

Gets the clipping rectangle.

Returns:

anychart.graphics.math.Rect - Returns rectangle settings.
Sets the clipping rectangle.

Params:

NameTypeDescription
valueanychart.graphics.math.Rect | stringClipping rectangle.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

color

Getter for the text color.

Returns:

string - The text color.
Setter for the text color.

Params:

NameTypeDefaultDescription
colorstring
'#000'
Text color.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

cursor

Getter for the cursor type.

Returns:

anychart.graphics.vector.Cursor - Returns cursor type.
Setter for the cursor type.

Params:

NameTypeDefaultDescription
valueanychart.graphics.vector.Cursor
null
Cursor type.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

decoration

Getter for the text decoration.

Returns:

string - Returns text decoration.
Setter for text decoration.

Params:

NameTypeDescription
valueanychart.graphics.vector.Text.Decoration | stringText decoration.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

desc

Getter for the element description value.

Returns:

string | null | undefined - The element description value.
Setter for the element description value.

Params:

NameTypeDescription
valuestring | nullValue to set.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

direction

Getter for the text direction.

Returns:

string - Returns text direction
Setter for text direction.

Params:

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

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

disablePointerEvents

Gets the value of the pointer events.

Returns:

boolean - Returns property value.
Disables the pointer events.

Params:

NameTypeDefaultDescription
valueboolean
false
Pointer events property value.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

disableStrokeScaling

Getter for the element's vector effect property.

Returns:

boolean - The vector effect property.
See listing
var element = stage.rect(10, 10, 100, 40);
var disableStrokeScaling = element.disableStrokeScaling();
Setter for the element's vector effect property.
Learn more by link.

Params:

NameTypeDefaultDescription
enabledboolean
false
Vector effect property to set.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

dispose

Disposes element completely. Removes it from the parent layer, sets links to null, removes it from DOM.

domElement

Returns DOM element if element is rendered.
In case of Stage in Suspended state or unbound element - null is returned.

Returns:

Element - DOM element.

drag

Returns the state flag.

Returns:

boolean | anychart.graphics.math.Rect - Absolute element bounds or flag.
Turns off/on dragging (moving) of an element.

Params:

NameTypeDefaultDescription
valueboolean | anychart.graphics.math.Rect
false
Flag or a dragging area.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

fontFamily

Getter for the font family of text.

Returns:

string - Returns font family.
Setter for font family of text.

Params:

NameTypeDefaultDescription
familystring
'Verdana'
Font family.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

fontSize

Getter for the font size of text.

Returns:

string | number - Returns font size.
Setter for font size of text.

Params:

NameTypeDefaultDescription
sizestring | number
'10px'
Font size.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

fontStyle

Getter for the font style of text.

Returns:

string - Returns font style.
Setter for font style of text.

Params:

NameTypeDescription
styleanychart.graphics.vector.Text.FontStyle | stringFont style.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

fontVariant

Getter for the font variant of text.

Returns:

string - Returns font variant
Setter for font variant of text.

Params:

NameTypeDescription
valueanychart.graphics.vector.Text.FontVariant | stringFont variant.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

fontWeight

Getter for the font weight of text.

Returns:

string - Returns font weight.
Setter for font weight of text.

Params:

NameTypeDescription
weightstring | numberFont weight.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

getAbsoluteBounds

Gets element bounds in absolute coordinates (root element coordinate system).

Returns:

anychart.graphics.math.Rect - Absolute element bounds.

getAbsoluteHeight

Returns height within root bounds.
See illustrations at anychart.graphics.vector.Element#getAbsoluteWidth

Returns:

number - Height.

getAbsoluteWidth

Returns width within root bounds.

Returns:

number - Width.

getAbsoluteX

Returns an absolute X (root element coordinate system).

Returns:

number - Absolute X.

getAbsoluteY

Returns an absolute Y (root element coordinate system).

Returns:

number - Absolute Y.

getBounds

Returns the bounds.

Returns:

anychart.graphics.math.Rect - Bounds.

getHeight

Returns the height.

Returns:

number - Height.

getRotationAngle

Returns the rotation angle in degrees.

Returns:

number - Rotation angle.

getStage

Stage object (to which the given element is bound).

Returns:

anychart.graphics.vector.Stage - Stage object.

getTextHeight

Returns actual text height.

Returns:

number - Text height.

getTextWidth

Returns actual text width.

Returns:

number - Text width

getTransformationMatrix

Returns the transformation matrix.

Returns:

Array.<number> - Transformation matrix array.

getWidth

Returns the width.

Returns:

number - Width.

getX

Returns X in the coordinate system of the parent.

Returns:

number - X in the coordinate system of the parent.

getY

Returns Y in the coordinate system of the parent.

Returns:

number - Y in the coordinate system of the parent.

hAlign

Getter for the horizontal align of text.

Returns:

string - Returns horizontal align.
Setter for horizontal align of text.

Params:

NameTypeDefaultDescription
alignanychart.graphics.vector.Text.HAlign | string
'start'
Horizontal align.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

hasParent

Whether parent element is set.

Returns:

boolean - Whether parent element is set.

height

Gets the height.
Note: it is not calculated automatically and has no default, and if it was not set using setter - NaN is returned.

Returns:

number | string - Returns height.
Sets a height.

Params:

NameTypeDescription
heightnumber | stringHeight to set.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

htmlText

Getter for the HTML format.

Returns:

string - Returns plain text.
Setter for the HTML format.

Params:

NameTypeDescription
valuestringText with HTML tags.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

id

Gets the element identifier.

Returns:

string - Returns element identifier.
Sets the element identifier.

Params:

NameTypeDescription
idstringCustom identifier.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

letterSpacing

Getter for the letter spacing of text.

Returns:

string - Returns letter spacing.
Setter for letter spacing of text.

Params:

NameTypeDescription
spacingstring | numberLetter spacing.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

lineHeight

Getter for the line height of text.

Returns:

string - Returns line height.
Sets line height, either as ratio or in pixels.

Params:

NameTypeDescription
heightstring | numberLetter height.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

listen

Adds an event listener.

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object):boolean|undefined
Callback method.
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

listenOnce

Adds an event listener that is removed automatically after the listener fired once.

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object):boolean|undefined
Callback method.
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

opacity

Getter for the text opacity.

Returns:

number - Returns text opacity.
Setter for text opacity.

Params:

NameTypeDescription
opacitynumberText opacity.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

parent

Returns the parent layer.

Returns:

anychart.graphics.vector.Layer | anychart.graphics.vector.Stage - Instance of element current layer.
Adds element to the given layer.

Params:

NameTypeDescription
parentanychart.graphics.vector.Layer | anychart.graphics.vector.StageParent layer.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

path

Getter for the path element.
See listing
var path = text.path();
Setter for the path element.

Params:

NameTypeDescription
pathanychart.graphics.vector.PathPath to set.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

remove

Current element removes itself from the parent layer.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

removeAllListeners

Removes all listeners from this listenable.

Params:

NameTypeDescription
typestringType of event to remove, default is to remove all types.

Returns:

number - Number of listeners removed.

rotate

Rotates a shape around the given rotation point.

Params:

NameTypeDescription
degreesnumberRotation angle in degrees.
cxnumberRotation point X.
cynumberRotation point Y.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

rotateByAnchor

Rotates a shape around the given anchor.

Params:

NameTypeDescription
degreesnumberRotation angle in degrees.
anchoranychart.graphics.vector.Anchor | stringRotation anchor.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

scale

Scales a shape. Scaling center is set in the coordinate system of the parent.

Params:

NameTypeDescription
sxnumberX scaling factor.
synumberY scaling factor.
cxnumberScaling point X.
cynumberScaling point Y.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

scaleByAnchor

Scales a shape by anchor. Scaling center is set as an anchor.

Params:

NameTypeDescription
sxnumberX scaling factor.
synumberY scaling factor.
anchoranychart.graphics.vector.Anchor | stringScaling anchor point.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

selectable

Getter for the text selectable property.

Returns:

boolean - Returns text selectable setting.
Setter for the text selectable property.
Defines whether text can be selected. If false - no selection.

Params:

NameTypeDefaultDescription
enabledboolean
true
Text selectable property.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

setPosition

Sets top left corner of a shape (transformation taken into account) in the coordinate system of the parent.

Params:

NameTypeDescription
xnumberX coordinate.
ynumberY coordinate.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

setRotation

Rotates a shape around the given point.

Params:

NameTypeDescription
degreesnumberRotation angle in degrees.
cxnumberRotation point X.
cynumberRotation point Y.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

setRotationByAnchor

Rotates a shape around the given anchor.

Params:

NameTypeDescription
degreesnumberRotation angle in degrees.
anchoranychart.graphics.vector.Anchor | stringRotation anchor.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

setTransformationMatrix

Sets the transformation matrix.

Params:

NameTypeDescription
m00numberScale X.
m10numberShear Y.
m01numberShear X.
m11numberScale Y.
m02numberTranslate X.
m12numberTranslate Y.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

style

Getter for the text style.

Returns:

anychart.graphics.vector.TextStyle - Returns text style.
Setter for the text style.

Params:

NameTypeDescription
styleanychart.graphics.vector.TextStyleText style.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

text

Getter for the text.

Returns:

string - Returns text.
Setter for the text.

Params:

NameTypeDescription
textstringPlain text.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

textIndent

Getter for the text indent.

Returns:

number - Returns text indent.
Setter for text indent.
The text-indent property specifies the indentation of the first line in a text-block.

Params:

NameTypeDescription
indentnumberText indent of text.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

textOverflow

Getter for the text overflow mode.

Returns:

string - Text overflow.
Setter for the text overflow mode.

Params:

NameTypeDescription
valueanychart.graphics.vector.Text.TextOverflow | stringText overflow.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

title

Getter for the element title value.

Returns:

string | null | undefined - The element title value.
Setter for the element title value.

Params:

NameTypeDescription
valuestring | nullValue to set.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

translate

Moves a shape taking an account the transformation.

Params:

NameTypeDescription
txnumberX movement amount.
tynumberY movement amount.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

unlisten

Removes an event listener which was added with listen() or listenOnce().

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object):boolean|undefined
Callback method.
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.

vAlign

Getter for the vertical align of text.

Returns:

string - Returns vertical align.
Setter for vertical align of text.

Params:

NameTypeDescription
alignanychart.graphics.vector.Text.VAlign | stringVertical align.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

visible

Gets the visibility flag.

Returns:

boolean - Returns the visibility flag.
Hides or shows an element.

Params:

NameTypeDefaultDescription
isVisibleboolean
true
Visibility flag.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

width

Gets the width.
Note: it is not calculated automatically and has no default, and if it was not set using setter - NaN is returned.

Returns:

number | string - Returns width.
Sets a width.

Params:

NameTypeDescription
widthnumber | stringWidth to set.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

wordBreak

Getter for word break of text. More at: Word-break Property

Returns:

string | anychart.graphics.vector.Text.WordBreak - Text word-break mode.
Setter for word break of text.

Params:

NameTypeDefaultDescription
valuestring | anychart.graphics.vector.Text.WordBreak
'normal'
Word-break mode.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

wordWrap

Getter for word-wrap of text.

Returns:

string | anychart.graphics.vector.Text.WordWrap - Text word-wrap mode.
Setter for word-wrap of text. More at: Word-wrap Property

Params:

NameTypeDefaultDescription
valuestring | anychart.graphics.vector.Text.WordWrap
'normal'
Word-wrap mode.

Returns:

string | anychart.graphics.vector.Text - Self instance for method chaining.

x

Getter for the X coordinate of text.

Returns:

number - Returns X coordinate.
Setter for X coordinate of text.

Params:

NameTypeDescription
xCoordnumberX coordinate.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

y

Getter for the Y coordinate of text.

Returns:

number - Returns Y coordinate.
Setter for Y coordinate of text.

Params:

NameTypeDescription
yCoordnumberY coordinate.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.

zIndex

Gets the element's zIndex.

Returns:

number - Z-index.
Sets the element's zIndex.

Params:

NameTypeDescription
valuenumberZ-index to set.

Returns:

anychart.graphics.vector.Text - Self instance for method chaining.