AnyChart
API Reference
Still have questions?
Contact support
Top
You are looking at an outdated v7 version of this document. Switch to the v8 version to see the up to date information.

class anychart.graphics.vector.Layer Improve this Doc

Extends: anychart.graphics.vector.Element

Layer class. Used to group elements.
Elements must be grouped if you want to apply similar changes to them, for example transformation.
Do not invoke constructor directly. Use anychart.graphics.vector.Stage#layer to create stage bound layer.
If you want to create an unbound layer – use anychart.graphics#layer
See also:
anychart.graphics.vector.Stage#layer,
anychart.graphics#layer
Elements indices (and layers indices within a stage) set Z-order.
The "higher" an element is, the greater its index.

Methods Overview

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 current 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 current rotation angle in degrees.
getTransformationMatrix()Returns the current 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.
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 current transformation.
zIndex()Z-index setting.
Miscellaneous
addChild()Add element to a layer, to the top (maximal index).
addChildAt()Adds an element to a layer by index.
attr()Attribute setting
circle()Invokes anychart.graphics.vector.Circle class constructor.
clip()Clipping setting.
cross()Draws a cross set by its circumscribed circle center and radius.
cursor()Cursor type.
desc()Description setting
diagonalCross()Draws a diagonal cross set by its circumscribed circle center and radius.
diamond()Draws a diamond set by its circumscribed circle center and radius.
disablePointerEvents()Pointer events setting.
disableStrokeScaling()Vector effect property
dispose()Disposes element completely.
domElement()Returns DOM element if element is rendered.
donut()Draws sector as donut chart element.
ellipse()Invokes anychart.graphics.vector.Ellipse class constructor.
forEachChild()Applies function to all elements in a layer.
getChildAt()Returns element by index.
getStage()Stage object (to which the given element is bound).
hLine()Draws a thick horizontal line set by its circumscribed circle center and radius.
hasChild()Checks if there is such element in children set.
hasParent()Whether parent element is set.
html()Invokes anychart.graphics.vector.Text class constructor and applies anychart.graphics.vector.Text#htmlText method
id()Element identifier
image()Invokes anychart.graphics.vector.Image class constructor.
indexOfChild()Looks for an element in a layer and returns index or -1, if not found.
layer()Invokes anychart.graphics.vector.Layer class constructor.
numChildren()Returns the number of children.
parent()Parent layer.
path()Invokes anychart.graphics.vector.Path class constructor.
pie()Draws sector as pie chart element.
rect()Invokes anychart.graphics.vector.Rect class constructor.
remove()Current element removes itself from the parent layer.
removeChild()Removes element from a layer.
removeChildAt()Removes element from a layer by index.
removeChildren()Removes all children from a layer.
roundedInnerRect()Draws rectangle with corners rounded inside.
roundedRect()Draws rectangle with rounded corners.
star()Draws multi-pointed star.
star10()Draws ten-pointed star.
star4()Draws four-pointed star.
star5()Draws five-pointed star.
star6()Draws six-pointed star.
star7()Draws seven-pointed star.
swapChildren()Swaps children.
swapChildrenAt()Swaps children by indexes.
text()Invokes anychart.graphics.vector.Text class constructor.
title()Title setting
triangleDown()Draws a triangle heading downwards set by its circumscribed circle center and radius.
triangleLeft()Draws a triangle heading leftwards set by its circumscribed circle center and radius.
triangleRight()Draws a triangle heading rightwards set by its circumscribed circle center and radius.
triangleUp()Draws a triangle heading upwards set by its circumscribed circle center and radius.
truncatedRect()Draws rectangle with cut corners.
vLine()Draws a thick vertical line set by its circumscribed circle center and radius.

Methods Description

addChild

Add element to a layer, to the top (maximal index).
All DOM changes will happen instantly, except anychart.graphics.vector.Stage#suspend.
Simplified version of anychart.graphics.vector.Layer#addChildAt where element is added to the end.

Params:

NameTypeDescription
elementanychart.graphics.vector.ElementElement to add.

Returns:

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

addChildAt

Adds an element to a layer by index.
Note: the greater index is - the 'higher' element is in a layer top element overlaps bottom elements.
All DOM changes will happen instantly, except anychart.graphics.vector.Stage#suspend.
Left image shows sequential calls of anychart.graphics.vector.Layer#addChild
Right image does the same, but star is added to 0 index.
.addChildAt(star5, 0); (see code of this image in samples).

Params:

NameTypeDescription
elementanychart.graphics.vector.ElementElement to add.
indexnumberElement index. Only positive numbers.

Returns:

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

appendTransformationMatrix

Combines the current transformation with the given transformation matrix.

Params:

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

Returns:

anychart.graphics.vector.Layer - 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.Layer - Self instance for method chaining.

circle

Invokes anychart.graphics.vector.Circle class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You have to take care of used objects yourself.
Read more at anychart.graphics.vector.Circle

Params:

NameTypeDescription
cxnumberCenter X, in pixels.
cynumberCenter Y, in pixels.
radiusnumberRadius, in pixels.

Returns:

anychart.graphics.vector.Circle - An instance of the class for method chaining.

clip

Gets the current clipping rectangle.

Returns:

anychart.graphics.math.Rect - An instance of the class for method chaining.
Sets the clipping rectangle.

Params:

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

Returns:

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

cross

Draws a cross set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#cross

cursor

Getter for the current cursor type.

Returns:

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

Params:

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

Returns:

anychart.graphics.vector.Layer - 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.Layer - Self instance for method chaining.

diagonalCross

Draws a diagonal cross set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#diagonalCross

diamond

Draws a diamond set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#diamond

disablePointerEvents

Gets the current 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.Layer - Self instance for method chaining.

disableStrokeScaling

Getter for the current element's vector effect property.

Returns:

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

Params:

NameTypeDefaultDescription
valueboolean
false
Vector effect property to set.

Returns:

anychart.graphics.vector.Layer - 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.

donut

Draws sector as donut chart element.
Read more at anychart.graphics.vector.primitives#donut

drag

Returns the current 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.Layer - Self instance for method chaining.

ellipse

Invokes anychart.graphics.vector.Ellipse class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You have to take care of used objects yourself.
Read more at anychart.graphics.vector.Ellipse

Params:

NameTypeDescription
cxnumberCenter X, in pixels.
cynumberCenter Y, in pixels.
rxnumberRadius X, in pixels.
rynumberRadius Y, in pixels.

Returns:

anychart.graphics.vector.Ellipse - An instance of the class for method chaining.

forEachChild

Applies function to all elements in a layer.

Params:

NameTypeDescription
callbackfunctionFunction to be applied.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.
Applies the function to all elements of a layer in the given context.

Params:

NameTypeDescription
callbackfunctionFunction to be applied.
thisObjectthis context for the function to be applied.

Returns:

anychart.graphics.vector.Layer - 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.

getChildAt

Returns element by index.

Params:

NameTypeDescription
indexnumberElement to be returned.

Returns:

anychart.graphics.vector.Layer - Element or null.

getHeight

Returns the height.

Returns:

number - Height.

getRotationAngle

Returns the current 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.

getTransformationMatrix

Returns the current 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.

hLine

Draws a thick horizontal line set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#hLine

hasChild

Checks if there is such element in children set.

Params:

NameTypeDescription
elementanychart.graphics.vector.ElementElement.

Returns:

boolean - True if it is a child.

hasParent

Whether parent element is set.

Returns:

boolean - Whether parent element is set.

html

Invokes anychart.graphics.vector.Text class constructor and applies anychart.graphics.vector.Text#htmlText method to handle HTML formatting.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You have to take care of used objects yourself.

Params:

NameTypeDescription
xnumberX-coordinate (Left) of top left corner of text bounds.
ynumberY-coordinate (Top) of top left corner of text bounds.
textstringText to be displayed.
styleanychart.graphics.vector.TextStyleText style. More at anychart.graphics.vector.Text#style.

Returns:

anychart.graphics.vector.Text - An instance of the class for method chaining.

id

Gets the current element identifier.

Returns:

string - Returns element identifier.
Sets the element identifier.

Params:

NameTypeDescription
valuestringCustom identifier.

Returns:

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

image

Invokes anychart.graphics.vector.Image class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.

Params:

NameTypeDescription
srcstringIRI (Internationalized Resource Identifiers) for image source.
xnumberX coordinate of left-top corner image.
ynumberY coordinate of left-top corner image.
widthnumberWidth of image bounds.
heightnumberHeight of image bounds.

Returns:

anychart.graphics.vector.Image - Image object instance.

indexOfChild

Looks for an element in a layer and returns index or -1, if not found.

Params:

NameTypeDescription
elementanychart.graphics.vector.ElementElement which index we need to find.

Returns:

number - Index or -1, or not found.

layer

Invokes anychart.graphics.vector.Layer class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You have to take care of used objects yourself.

Returns:

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

listen

Adds an event listener.

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction
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
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.

numChildren

Returns the number of children.

Returns:

number - Number of children.

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
valueanychart.graphics.vector.Layer | anychart.graphics.vector.StageParent layer.

Returns:

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

path

Invokes anychart.graphics.vector.Path class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You have to take care of used objects yourself.
Read more at: anychart.graphics.vector.Path

Returns:

anychart.graphics.vector.Path - An instance of the class for method chaining.

pie

Draws sector as pie chart element.
Read more at anychart.graphics.vector.primitives#pie

rect

Invokes anychart.graphics.vector.Rect class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You have to take care of used objects yourself.

Params:

NameTypeDescription
xnumberX (Left) of top left rectangle corner.
ynumberY (Top) of to left rectangle corner.
widthnumberRectangle width.
heightnumberRectangle height.

Returns:

anychart.graphics.vector.Rect - An instance of the class for method chaining.

remove

Current element removes itself from the parent layer.

Returns:

anychart.graphics.vector.Layer - 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.

removeChild

Removes element from a layer.
All changes in DOM will happen instantly, except anychart.graphics.vector.Stage#suspend.
Note: this method doesn't remove element, it just breaks the link between the element and the layer.
This is an extension of anychart.graphics.vector.Layer#removeChildAt method.

Params:

NameTypeDescription
elementanychart.graphics.vector.ElementElement to remove or its id.

Returns:

anychart.graphics.vector.Layer - Removed element or null.

removeChildAt

Removes element from a layer by index.
All changes in DOM will happen instantly, except anychart.graphics.vector.Stage#suspend.
Note: this method doesn't remove element, it just breaks the link between the element and the layer.

Params:

NameTypeDescription
indexnumberIndex of element to be removed.

Returns:

anychart.graphics.vector.Layer - Removed element or null.

removeChildren

Removes all children from a layer.

Returns:

Array.<anychart.graphics.vector.Element> - Array of removed elements.

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.Layer - 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.Layer - Self instance for method chaining.

roundedInnerRect

Draws rectangle with corners rounded inside.
Read more at anychart.graphics.vector.primitives#roundedInnerRect

roundedRect

Draws rectangle with rounded corners.
Read more at anychart.graphics.vector.primitives#roundedRect

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.Layer - 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.Layer - 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.Layer - 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.Layer - 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.Layer - 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.Layer - Self instance for method chaining.

star

Draws multi-pointed star.
Read more at anychart.graphics.vector.primitives#star

star10

Draws ten-pointed star.
Read more at anychart.graphics.vector.primitives#star10

star4

Draws four-pointed star.
Read more at anychart.graphics.vector.primitives#star4

star5

Draws five-pointed star.
Read more at anychart.graphics.vector.primitives#star5

star6

Draws six-pointed star.
Read more at anychart.graphics.vector.primitives#star6

star7

Draws seven-pointed star.
Read more at anychart.graphics.vector.primitives#star7

swapChildren

Swaps children.

Params:

NameTypeDescription
element1anychart.graphics.vector.ElementFirst element.
element2anychart.graphics.vector.ElementSecond element.

Returns:

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

swapChildrenAt

Swaps children by indexes.

Params:

NameTypeDescription
index1numberFirst element index.
index2numberSecond element index.

Returns:

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

text

Invokes anychart.graphics.vector.Text class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You have to take care of used objects yourself.

Params:

NameTypeDescription
xnumberX-coordinate (Left) of left top corner of text bounds.
ynumberY-coordinate (Top) of left top corner of text bounds.
textstringText to be displayed.
styleanychart.graphics.vector.TextStyleText style. More at anychart.graphics.vector.Text#style.

Returns:

anychart.graphics.vector.Text - An instance of the class 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.Layer - Self instance for method chaining.

translate

Moves a shape taking an account the current transformation.

Params:

NameTypeDescription
txnumberX movement amount.
tynumberY movement amount.

Returns:

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

triangleDown

Draws a triangle heading downwards set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#triangleDown

triangleLeft

Draws a triangle heading leftwards set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#triangleLeft

triangleRight

Draws a triangle heading rightwards set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#triangleRight

triangleUp

Draws a triangle heading upwards set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#triangleUp

truncatedRect

Draws rectangle with cut corners.
Read more at anychart.graphics.vector.primitives#truncatedRect

unlisten

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

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction
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.

vLine

Draws a thick vertical line set by its circumscribed circle center and radius.
Read more at anychart.graphics.vector.primitives#vLine

visible

Gets the current visibility flag.

Returns:

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

Params:

NameTypeDefaultDescription
isVisibleboolean
true
Visibility flag.

Returns:

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

zIndex

Gets the current element's zIndex.

Returns:

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

Params:

NameTypeDescription
valuenumberZ-index to set.

Returns:

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