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
Illustration shows a shape transformation with the several calls of
.appendTransformationMatrix(0, 0.5, 1, 0, 0, 0)
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.Text - Self instance for method chaining.Try it:
attr
Params:
Name | Type | Description |
---|---|---|
key | string | Name of attribute. |
Returns:
* - Attribute value.Try it:
Params:
Name | Type | Description |
---|---|---|
key | string | Name of attribute. |
value | * | Value of attribute. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
clip
Returns:
anychart.graphics.math.Rect - Returns rectangle settings.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.Text - Self instance for method chaining.Try it:
color
Params:
Name | Type | Default | Description |
---|---|---|---|
color | string | '#000' | Text color. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
cursor
Params:
Name | Type | Default | Description |
---|---|---|---|
value | anychart.graphics.vector.Cursor | null | Cursor type. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
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:
desc
Returns:
string | null | undefined - The element description value.Try it:
Params:
Name | Type | Description |
---|---|---|
value | string | null | Value to set. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
direction
Params:
Name | Type | Default | Description |
---|---|---|---|
direction | anychart.graphics.vector.Text.Direction | string | 'ltr' | Text direction. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
disablePointerEvents
Params:
Name | Type | Default | Description |
---|---|---|---|
value | boolean | false | Pointer events property value. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
disableStrokeScaling
Returns:
boolean - The vector effect property.var element = stage.rect(10, 10, 100, 40); var disableStrokeScaling = element.disableStrokeScaling();
Learn more by link.
Params:
Name | Type | Default | Description |
---|---|---|---|
enabled | boolean | false | Vector effect property to set. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
dispose
Try it:
domElement
In case of Stage in Suspended state or unbound element - null is returned.
Returns:
Element - DOM element.drag
Returns:
boolean | anychart.graphics.math.Rect - Absolute element bounds or flag.Try it:
Params:
Name | Type | Default | Description |
---|---|---|---|
value | boolean | anychart.graphics.math.Rect | false | Flag or a dragging area. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
fontFamily
Params:
Name | Type | Default | Description |
---|---|---|---|
family | string | 'Verdana' | Font family. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
fontSize
Params:
Name | Type | Default | Description |
---|---|---|---|
size | string | number | '10px' | Font size. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
fontStyle
Params:
Name | Type | Description |
---|---|---|
style | anychart.graphics.vector.Text.FontStyle | string | Font style. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
fontVariant
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
Params:
Name | Type | Description |
---|---|---|
weight | string | number | Font weight. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
getAbsoluteBounds
Returns:
anychart.graphics.math.Rect - Absolute element bounds.Try it:
getAbsoluteHeight
See illustrations at anychart.graphics.vector.Element#getAbsoluteWidth
Returns:
number - Height.Try it:
getAbsoluteWidth
getAbsoluteX
Returns:
number - Absolute X.Try it:
getAbsoluteY
Returns:
number - Absolute Y.Try it:
getBounds
getHeight
getRotationAngle
getStage
Returns:
anychart.graphics.vector.Stage - Stage object.Try it:
getTextHeight
getTextWidth
getTransformationMatrix
[
{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.Try it:
getWidth
getX
Returns:
number - X in the coordinate system of the parent.Try it:
getY
Returns:
number - Y in the coordinate system of the parent.Try it:
hAlign
Returns:
string - Returns horizontal align.Try it:
Params:
Name | Type | Default | Description |
---|---|---|---|
align | anychart.graphics.vector.Text.HAlign | string | 'start' | Horizontal align. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
hasParent
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.Try it:
Params:
Name | Type | Description |
---|---|---|
height | number | string | Height to set. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
htmlText
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
Returns:
string - Returns element identifier.Try it:
Params:
Name | Type | Description |
---|---|---|
id | string | Custom identifier. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
letterSpacing
Params:
Name | Type | Description |
---|---|---|
spacing | string | number | Letter spacing. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
lineHeight
Params:
Name | Type | Description |
---|---|---|
height | string | number | Letter height. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
listen
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(e:Object):boolean|undefined | 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:
listenOnce
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(e:Object):boolean|undefined | 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:
opacity
Params:
Name | Type | Description |
---|---|---|
opacity | number | Text opacity. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
parent
Returns:
anychart.graphics.vector.Layer | anychart.graphics.vector.Stage - Instance of element current layer.Try it:
Params:
Name | Type | Description |
---|---|---|
parent | anychart.graphics.vector.Layer | anychart.graphics.vector.Stage | Parent layer. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
path
Returns:
anychart.graphics.vector.Path -var path = text.path();
Params:
Name | Type | Description |
---|---|---|
path | anychart.graphics.vector.Path | Path to set. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
remove
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
removeAllListeners
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:
rotate
Left illustration shows 20 degrees rotation with the default rotation point.
.rotate(20)
Right illustration shows 20 degrees rotation with the given rotation point.
.rotate(20, x, y)
Rotation points are marked with red, initial position of shapes is marked with gray.
Params:
Name | Type | Description |
---|---|---|
degrees | number | Rotation angle in degrees. |
cx | number | Rotation point X. |
cy | number | Rotation point Y. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
rotateByAnchor
Left illustration shows 90 degrees rotation around the default anchor.
.rotateByAnchor(90)
Right illustration shows 90 degrees rotation around the given anchor.
.rotateByAnchor(90, anychart.graphics.vector.Anchor.CENTER_TOP)
Rotation points are marked with red, initial position of shapes is marked with gray.
Params:
Name | Type | Description |
---|---|---|
degrees | number | Rotation angle in degrees. |
anchor | anychart.graphics.vector.Anchor | string | Rotation anchor. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
scale
Left illustration shows default point scaling.
.scale(0.5, 0.5,)
Right illustration shows scaling with the scaling center set.
.scale(0.5, 0.5, x, y)
Scaling center is marked with red, initial state is marked with gray.
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.Text - Self instance for method chaining.Try it:
scaleByAnchor
Left illustration shows scaling with the default anchor.
.scaleByAnchor(0.5, 0.5)
Right illustration shows scaling with the anchor set.
.scaleByAnchor(0.5, 0.5, anychart.graphics.vector.Anchor.RIGHT_TOP)
Scaling center is marked with red, initial state is marked with gray.
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.Text - Self instance for method chaining.Try it:
selectable
Returns:
boolean - Returns text selectable setting.Try it:
Defines whether text can be selected. If false - no selection.
Params:
Name | Type | Default | Description |
---|---|---|---|
enabled | boolean | true | Text selectable property. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
setPosition
Params:
Name | Type | Description |
---|---|---|
x | number | X coordinate. |
y | number | Y coordinate. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
setRotation
Params:
Name | Type | Description |
---|---|---|
degrees | number | Rotation angle in degrees. |
cx | number | Rotation point X. |
cy | number | Rotation point Y. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
setRotationByAnchor
Params:
Name | Type | Description |
---|---|---|
degrees | number | Rotation angle in degrees. |
anchor | anychart.graphics.vector.Anchor | string | Rotation anchor. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
setTransformationMatrix
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.Text - Self instance for method chaining.Try it:
style
Params:
Name | Type | Description |
---|---|---|
style | anychart.graphics.vector.TextStyle | Text style. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
text
Params:
Name | Type | Description |
---|---|---|
text | string | Plain text. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
textIndent
The text-indent property specifies the indentation of the first line in a text-block.
Params:
Name | Type | Description |
---|---|---|
indent | number | Text indent of text. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
textOverflow
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:
title
Returns:
string | null | undefined - The element title value.Try it:
Params:
Name | Type | Description |
---|---|---|
value | string | null | Value to set. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
translate
Illustration shows a shape movement when
.translate(20, 10)
is invoked several times.Params:
Name | Type | Description |
---|---|---|
tx | number | X movement amount. |
ty | number | Y movement amount. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
unlisten
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(e:Object):boolean|undefined | 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:
vAlign
Params:
Name | Type | Description |
---|---|---|
align | anychart.graphics.vector.Text.VAlign | string | Vertical align. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
visible
Params:
Name | Type | Default | Description |
---|---|---|---|
isVisible | boolean | true | Visibility flag. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
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.Try it:
Params:
Name | Type | Description |
---|---|---|
width | number | string | Width to set. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
wordBreak
Returns:
string | anychart.graphics.vector.Text.WordBreak - Text word-break mode.Try it:
Params:
Name | Type | Default | Description |
---|---|---|---|
value | string | anychart.graphics.vector.Text.WordBreak | 'normal' | Word-break mode. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
wordWrap
Returns:
string | anychart.graphics.vector.Text.WordWrap - Text word-wrap mode.Try it:
Params:
Name | Type | Default | Description |
---|---|---|---|
value | string | anychart.graphics.vector.Text.WordWrap | 'normal' | Word-wrap mode. |
Returns:
string | anychart.graphics.vector.Text - Self instance for method chaining.Try it:
x
Params:
Name | Type | Description |
---|---|---|
xCoord | number | X coordinate. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
y
Params:
Name | Type | Description |
---|---|---|
yCoord | number | Y coordinate. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it:
zIndex
Params:
Name | Type | Description |
---|---|---|
value | number | Z-index to set. |
Returns:
anychart.graphics.vector.Text - Self instance for method chaining.Try it: