AnyChart
API Reference
Still have questions?
Contact support
Top
You are looking at an outdated 7.7.0 version of this document. Switch to the 8.4.0 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

Methods Overview

Miscellaneous
addChild()Add element to a layer, to the top (maximal index).
addChildAt()Adds an element to a layer by index.
circle()Invokes anychart.graphics.vector.Circle class constructor.
ellipse()Invokes anychart.graphics.vector.Ellipse class constructor.
forEachChild()Applies function to all elements in a layer.
getChildAt()Returns element by index.
hasChild()Checks if there is such element in children set.
html()Returns anychart.graphics.vector.Text constructoe and applies anychart.graphics.vector.Text#htmlText to handle HTML formatting.
image()Invokes anychart.graphics.vector.Image class constructor.
indexOfChild()Looks for an element in a layer and returns index or -1, of not found.
layer()Invokes anychart.graphics.vector.Layer class constructor.
numChildren()Returns the number of children.
path()Invokes anychart.graphics.vector.Path class constructor.
rect()Invokes anychart.graphics.vector.Rect class constructor.
removeChild()Removes element from a layer.
removeChildAt()Removes element from a layer by index.
removeChildren()Remove all children from a layer.
swapChildren()Swap children.
swapChildrenAt()Swap children by indices.
text()Invokes anychart.graphics.vector.Text class constructor.

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.

Params:

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

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 need to take care of used objects yourself.
Read more at anychart.graphics.vector.Circle

Params:

NameTypeDescription
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param
cxnumberCenter X, in pixels.
cynumberCenter Y, in pixels.
radiusnumberRadius, in pixels.

Returns:

anychart.graphics.vector.Circle - An instance of class 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 need to take care of used objects yourself.
Read more at anychart.graphics.vector.Ellipse

Params:

NameTypeDescription
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param
cxnumberCenter X, in pixels.
cynumberCenter Y, in pixels.
rxnumberRadius X, in pixels.
rynumberRadius Y, in pixels.

Returns:

anychart.graphics.vector.Ellipse - An instance of 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.

getChildAt

Returns element by index.

Params:

NameTypeDescription
indexnumberElement to be returned.

Returns:

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

hasChild

Checks if there is such element in children set.

Params:

NameTypeDescription
elementanychart.graphics.vector.ElementElement.

Returns:

boolean - True if it is a child.

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 need to take care of used objects yourself.

Params:

NameTypeDescription
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param
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 class 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
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param
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, of 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 need to take care of used objects yourself.

Params:

NameTypeDescription
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param

Returns:

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

numChildren

Returns the number of children.

Returns:

number - Number of children.

path

Invokes anychart.graphics.vector.Path 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.
Read more at: anychart.graphics.vector.Path

Params:

NameTypeDescription
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param

Returns:

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

rect

Invokes anychart.graphics.vector.Rect 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
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param
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 class for method chaining.

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

Remove all children from a layer.

Returns:

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

swapChildren

Swap children.

Params:

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

Returns:

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

swapChildrenAt

Swap children by indices.

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 need to take care of used objects yourself.

Params:

NameTypeDescription
this{anychart.graphics.vector.Layer|anychart.graphics.vector.Stage}This param
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 class for method chaining.