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

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.

Methods Overview

Miscellaneous
appendTransformationMatrix()Combines the current transformation with the given transformation matrix.
clip()Sets clipping rectangle.
color()Getter for text color.
cursor()Getter for cursor type.
decoration()Getter for text decoration.
direction()Getter for text direction.
disablePointerEvents()Specifies under what circumstances a given graphics element can be a target element for a pointer event.
domElement()Returns DOM element if element is rendered.
drag()Turns off/on dragging (moving) of an element.
fontFamily()Getter for font family of text.
fontSize()Getter for font size of text.
fontStyle()Getter for font style of text.
fontVariant()Getter for font variant of text.
fontWeight()Getter for font weight of text.
getAbsoluteBounds()Gets element bounds in absolute coordinates (root element coordinate system).
getAbsoluteCoordinate()Returns absolute coordinates (root element coordinate system).
getAbsoluteHeight()Returns height within root bounds.
getAbsoluteSize()Returns size 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 bounds.
getCoordinate()Returns (X,Y) in the coordinate system of the parent.
getHeight()Returns height.
getRotationAngle()Returns the current rotation angle in degrees.
getSize()Returns size.
getStage()Stage object (to which the given element is bound).
getTransformationMatrix()Returns the current transformation matrix.
getWidth()Returns width.
getX()Returns X in the coordinate system of the parent.
getY()Returns Y in the coordinate system of the parent.
hAlign()Getter for horizontal align of text.
hasParent()Whether parent element is set.
height()Returns height.
htmlText()Set up text in HTML format. Incoming text is parsed HTML parser.
id()Gets element identifier. If it was not set, it will be generated and applied to the DOM.
letterSpacing()Getter for letter spacing of text.
lineHeight()Getter for line height of text.
listen()Adds an event listener. A listener can only be added once to an
listenOnce()Adds an event listener that is removed automatically after the
opacity()Getter for text opacity.
parent()Returns the parent layer.
remove()Current element removes itself from the parent layer.
removeAllListeners()Removes all listeners from this listenable. If type is specified,
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. Scaling center is set as an anchor.
selectable()Getter for text selectable property.
setPosition()Sets top left corner of a shape (transformation taken into account) in the coordinate system of the parent.
setRotation()Rotatates a shape around the given point.
setRotationByAnchor()Rotates a shape around the given anchor.
setTransformationMatrix()Sets transformation matrix.
style()Getter for style.
text()Get current text.
textIndent()Getter for text indent.
textOverflow()Getter for font text overflow of text.
textWrap()Getter for text wrap of text.
translate()Moves a shape taking an account the current transformation.
unlisten()Removes an event listener which was added with listen() or listenOnce().
vAlign()Getter for vertical align of text.
visible()Gets/sets the current visibility flag.
width()Returns width.
x()Getter for X coordinate of text.
y()Getter for Y coordinate of text.
zIndex()Gets and sets element's zIndex.

Methods Description

appendTransformationMatrix

Combines the current transformation with the given transformation matrix. Combination is done via matrix multiplication (multiplication to the right).

Params:

Name Type Description
m00 number Scale X.
m10 number Shear Y.
m01 number Shear X.
m11 number Scale Y.
m02 number Translate X.
m12 number Translate Y.

Returns:

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

clip

Gets/sets clipping rectangle.

Returns:

anychart.graphics.math.Rect - An instance of class for method chaining.
Sets clipping rectangle. Affects display only after render() method call.
Attention! In SVG clip will transform according to transformation, and in VML clip will be surrounding.

Params:

Name Type Description
value anychart.graphics.math.Rect | string Clipping rectangle.

Returns:

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

color

Getter for text color.

Returns:

string -
Setter for text color.

Params:

Name Type Description
value string Text color.

Returns:

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

Try it:

cursor

Getter for cursor type.

Returns:

anychart.graphics.vector.Cursor - Current cursor type.
Setter for cursor type.

Params:

Name Type Description
value anychart.graphics.vector.Cursor Cursor type.

Returns:

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

decoration

Getter for text decoration.

Returns:

string -
Setter for text decoration.

Params:

Name Type Description
value anychart.graphics.vector.Text.Decoration | string Text decoration.

Returns:

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

Try it:

direction

Getter for text direction.

Returns:

string -
Setter for text direction.

Params:

Name Type Description
value anychart.graphics.vector.Text.Direction | string Text direction.

Returns:

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

Try it:

disablePointerEvents

Specifies under what circumstances a given graphics element can be a target element for a pointer event.

Params:

Name Type Description
value boolean Pointer events property value.

Returns:

anychart.graphics.vector.Element boolean - If opt_value defined then returns Element object for chaining else returns property value.

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 current state flag.

Returns:

boolean anychart.graphics.math.Rect - .
Turns off/on dragging (moving) of an element.
Sets mode (true - on, false - off) or dragging area for an element, dragging is always on within an area.

Params:

Name Type Description
value boolean | anychart.graphics.math.Rect Flag or a dragging area.

Returns:

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

Try it:

fontFamily

Getter for font family of text.

Returns:

string -
Setter for font family of text.

Params:

Name Type Description
value string Font family.

Returns:

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

Try it:

fontSize

Getter for font size of text.

Returns:

string number -
Setter for font size of text.

Params:

Name Type Description
value string | number Font size.

Returns:

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

Try it:

fontStyle

Getter for font style of text.

Returns:

string -
Setter for font style of text.

Params:

Name Type Description
value anychart.graphics.vector.Text.FontStyle | string Font style.

Returns:

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

Try it:

fontVariant

Getter for font variant of text.

Returns:

string -
Setter for font variant of text.

Params:

Name Type Description
value anychart.graphics.vector.Text.FontVariant | string Font variant.

Returns:

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

Try it:

fontWeight

Getter for font weight of text.

Returns:

string -
Setter for font weight of text.

Params:

Name Type Description
value string | number Font weight.

Returns:

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

Try it:

getAbsoluteBounds

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

Returns:

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

getAbsoluteCoordinate

Returns absolute coordinates (root element coordinate system).
See illustrations at anychart.graphics.vector.Element#getAbsoluteX and anychart.graphics.vector.Element#getAbsoluteY

Returns:

anychart.graphics.math.Coordinate - Absolute coordinates.

getAbsoluteHeight

Returns height within root bounds.

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 bounds.

Returns:

anychart.graphics.math.Rect - Bounds.

getCoordinate

Returns (X,Y) in the coordinate system of the parent.

Returns:

anychart.graphics.math.Coordinate - (X,Y) in the coordinate system of the parent.

getHeight

Returns height.

Returns:

number - Height.

getRotationAngle

Returns the current rotation angle in degrees.

Returns:

number - Rotation angle.

getSize

Returns size.

Returns:

anychart.graphics.math.Size - Size.

getStage

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

Returns:

anychart.graphics.vector.Stage - Stage object.

getTransformationMatrix

Returns the current transformation matrix as an array of six elements:
[
  {number} m00 Scale X.
  {number} m10 Shear Y.
  {number} m01 Shear X.
  {number} m11 Scale Y.
  {number} m02 Translate X.
  {number} m12 Translate Y.
]

Returns:

Array.<number> - Transformation matrix array.

getWidth

Returns 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 horizontal align of text.

Returns:

string -
Setter for horizontal align of text.

Params:

Name Type Description
value anychart.graphics.vector.Text.HAlign | string Horizontal align.

Returns:

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

Try it:

hasParent

Whether parent element is set.

Returns:

boolean - Whether parent element is set.

height

Returns 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 -
Sets height.

Params:

Name Type Description
value number | string Height.

Returns:

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

Try it:

htmlText

Get current text.

Returns:

string - Current plain text.
Set up text in HTML format. Incoming text is parsed HTML parser. The tags that define style will taken into consideration and applied to the final result. HTML tags supported:
  • <br> (<br/>)
  • <b></b>, <strong></strong>
  • <i></i>, <em></em>
  • <span></span> (font-style, font-variant, font-family, font-size, font-weight, color, letter-spacing, text-decoration, opacity)

Params:

Name Type Description
value string Text with HTML tags.

Returns:

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

Try it:

id

Gets element identifier. If it was not set, it will be generated and applied to the DOM.

Returns:

string - Returns element identifier.
Sets element identifier.

Params:

Name Type Description
value string Custom identifier.

Returns:

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

letterSpacing

Getter for letter spacing of text.

Returns:

string -
Setter for letter spacing of text.

Params:

Name Type Description
value string | number Letter spacing.

Returns:

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

Try it:

lineHeight

Getter for line height of text.

Returns:

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

Params:

Name Type Description
value string | number Letter height.

Returns:

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

Try it:

listen

Adds an event listener. A listener can only be added once to an object and if it is added again the key for the listener is returned. Note that if the existing listener is a one-off listener (registered via listenOnce), it will no longer be a one-off listener after a call to listen().

Params:

Name Type Description
type string The event type id.
listener function Callback method.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope SCOPE 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. If an existing listener already exists, listenOnce will do nothing. In particular, if the listener was previously registered via listen(), listenOnce() will not turn the listener into a one-off listener. Similarly, if there is already an existing one-off listener, listenOnce does not modify the listeners (it is still a once listener).

Params:

Name Type Description
type string The event type id.
listener function Callback method.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope SCOPE Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

opacity

Getter for text opacity.

Returns:

number -
Setter for text opacity.

Params:

Name Type Description
value number Text opacity.

Returns:

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

Try it:

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:

Name Type Description
value anychart.graphics.vector.Layer | anychart.graphics.vector.Stage Parent layer.

Returns:

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

remove

Current element removes itself from the parent layer.

Returns:

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

removeAllListeners

Removes all listeners from this listenable. If type is specified, it will only remove listeners of the particular type. otherwise all registered listeners will be removed.

Params:

Name Type Description
type string Type 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:

Name Type Description
degrees number Rotation angle in degrees.
cx number Rotation point X.
cy number Rotation point Y.

Returns:

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

rotateByAnchor

Rotates a shape around the given anchor.

Params:

Name Type Description
degrees number Rotation angle in degress.
anchor anychart.graphics.vector.Anchor | string Rotation anchor.

Returns:

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

scale

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

Params:

Name Type Description
sx number X scaling factor.
sy number Y scaling factor.
cx number Scaling point X.
cy number Scaling point Y.

Returns:

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

scaleByAnchor

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

Params:

Name Type Description
sx number X scaling factor.
sy number Y scaling factor.
anchor anychart.graphics.vector.Anchor | string Scaling anchor point.

Returns:

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

selectable

Getter for text selectable property.

Returns:

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

Params:

Name Type Description
value boolean Text selectable property.

Returns:

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

Try it:

setPosition

Sets top left corner of a shape (transformation taken into account) in the coordinate system of the parent.
Note: See illustration at anychart.graphics.vector.Element#translate, the only difference between anychart.graphics.vector.Element#translate and this method is the fact that that this method resets the current transformation, and and anychart.graphics.vector.Element#translate adds movement to the existing transformation.

Params:

Name Type Description
x number X coordinate.
y number Y coordinate.

Returns:

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

setRotation

Rotates a shape around the given point.
Note: See illustration at anychart.graphics.vector.Element#rotate, the only difference between anychart.graphics.vector.Element#rotate and this method is the fact that this method resets the current transformation, and anychart.graphics.vector.Element#rotate adds rotation to the existing transformation.

Params:

Name Type Description
degrees number Rotation angle in degrees.
cx number Rotation point X.
cy number Rotation point Y.

Returns:

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

setRotationByAnchor

Rotates a shape around the given anchor.
Note: See illustration at anychart.graphics.vector.Element#rotateByAnchor, the only difference between anychart.graphics.vector.Element#rotateByAnchor and this method is the fact that this method resets the current transformation, and and anychart.graphics.vector.Element#rotate adds rotation to the existing transformation.

Params:

Name Type Description
degrees number Rotation angle in degrees.
anchor anychart.graphics.vector.Anchor | string Rotation anchor.

Returns:

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

setTransformationMatrix

Sets transformation matrix.
Note: See illustration at anychart.graphics.vector.Element#appendTransformationMatrix, the difference between anychart.graphics.vector.Element#appendTransformationMatrix and this method is that anychart.graphics.vector.Element#appendTransformationMatrix combined transformation with the current, and this method resets the current.

Params:

Name Type Description
m00 number Scale X.
m10 number Shear Y.
m01 number Shear X.
m11 number Scale Y.
m02 number Translate X.
m12 number Translate Y.

Returns:

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

style

Getter for style.
Sets style.

Params:

Name Type Description
value anychart.graphics.vector.TextStyle Style.

Returns:

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

Try it:

text

Get current text.

Returns:

string - Current text.
Set up plain text. Text will be take as is. All symbols will be displaying in result.

Params:

Name Type Description
value string Plaint text.

Returns:

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

Try it:

textIndent

Getter for text indent.

Returns:

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

Params:

Name Type Description
value number Text indent of text.

Returns:

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

Try it:

textOverflow

Getter for font text overflow of text.

Returns:

string -
Setter for font text overflow of text.

Params:

Name Type Description
value anychart.graphics.vector.Text.TextOverflow | string Text overflow.

Returns:

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

Try it:

textWrap

Getter for text wrap of text.

Returns:

string -
Setter for text wrap of text.

Params:

Name Type Description
value anychart.graphics.vector.Text.TextWrap | string Text wrap.

Returns:

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

Try it:

translate

Moves a shape taking an account the current transformation. Movement happens in a shape coordinate system (not the coordinate system of the parent).

Params:

Name Type Description
tx number X movement amount.
ty number Y movement amount.

Returns:

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

unlisten

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

Params:

Name Type Description
type string The event type id.
listener function Callback method.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope SCOPE Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.

vAlign

Getter for vertical align of text.

Returns:

string -
Setter for vertical align of text.

Params:

Name Type Description
value anychart.graphics.vector.Text.VAlign | string Vertical align.

Returns:

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

Try it:

visible

Gets/sets the current visibility flag.

Returns:

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

Params:

Name Type Description
isVisible boolean Visibility flag.

Returns:

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

Try it:

width

Returns 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 -
Sets width.

Params:

Name Type Description
value number | string Width.

Returns:

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

Try it:

x

Getter for X coordinate of text.

Returns:

number -
Setter for X coordinate of text.

Params:

Name Type Description
value number X coordinate.

Try it:

y

Getter for Y coordinate of text.

Returns:

number -
Setter for Y coordinate of text.

Params:

Name Type Description
value number Y coordinate.

Try it:

zIndex

Gets and sets element's zIndex.

Params:

Name Type Description
value number Z index to set.

Returns:

number anychart.graphics.vector.Element - Z index or itself for chaining.