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

class anychart.data.Tree Improve this Doc

Extends: anychart.Base

Tree data implementation.

Methods Overview

Miscellaneous
addChild()Adds a new root element.
addChildAt()Inserts a new root element into a specified position.
addData()Adds a data.
createIndexOn()Creates an index on a specified field.
getChildAt()Gets the child by index.
getChildren()Returns a copy of roots array.
getTraverser()Creates tree data traverser.
indexOfChild()Gets index of child in a roots array.
numChildren()Returns a length of roots array.
removeChild()Removes tree's root data item.
removeChildAt()Removes child at specified position.
removeChildren()Removes children.
removeIndexOn()Removes index on a specified field.
search()Performs a data search. Returns null of nothing is found, tree data item if here's a single result and array of
searchItems()Performs a data search. Actually does the same as (@see search) but result is always an array.

Methods Description

addChild

Adds a new root element.

Params:

Name Type Description
child Object Child object.

Returns:

anychart.data.Tree - - Itself for method chaining.

addChildAt

Inserts a new root element into a specified position.

Params:

Name Type Description
child Object Child object.
index number Position.

Returns:

anychart.data.Tree - - Itself for method chaining.

addData

Adds a data.

Params:

Name Type Description
data Array.<Object> Raw data.
fillingMethod anychart.enums.TreeFillingMethod | string Filling method.

Returns:

anychart.data.Tree - - Itself for method chaining.

createIndexOn

Creates an index on a specified field. It can't be indexed by 'parent' or 'children' fields because these fields are not available by treeItem.get(field); (@see createComparisonFunction).

Params:

Name Type Description
field string Field name.

Returns:

anychart.data.Tree - - Itself for method chaining.

getChildAt

Gets the child by index.

Params:

Name Type Description
index number Index of child to find.

Returns:

anychart.data.Tree.DataItem undefined - - Child into a specified position.

getChildren

Returns a copy of roots array.

Returns:

Array.<anychart.data.Tree.DataItem> - - Copy of roots array.

getTraverser

Creates tree data traverser.

Returns:

anychart.data.Traverser - - New traverser.

indexOfChild

Gets index of child in a roots array.

Params:

Name Type Description
child anychart.data.Tree.DataItem Sought child.

Returns:

number - - Index of child.

numChildren

Returns a length of roots array.

Returns:

number - - Number of roots.

removeChild

Removes tree's root data item.

Params:

Name Type Description
child anychart.data.Tree.DataItem Child to be removed.

Returns:

anychart.data.Tree.DataItem - - Itself for method chaining.

removeChildAt

Removes child at specified position.

Params:

Name Type Description
index number Index of item to be removed.

Returns:

anychart.data.Tree.DataItem - - Removed item or null if item is not found.

removeChildren

Removes children.

Returns:

anychart.data.Tree - - Itself for method chaining.

removeIndexOn

Removes index on a specified field.

Params:

Name Type Description
field string Field name.

Returns:

anychart.data.Tree - - Itself for method chaining.

searchItems

Performs a data search. Actually does the same as (@see search) but result is always an array.

Params:

Name Type Description
soughtField string Field for search. Literally means the name of field of data item.
valueOrEvaluator string | number | boolean | function | function Sought value or evaluator function. Evaluator function that receives 3 arguments (the element, the index and the array). Should return a negative number, zero, or a positive number depending on whether the desired index is before, at, or after the element passed to it.
comparisonFnOrEvaluatorContext function | Object Custom comparison function or evaluator context. Optional comparison function by which the array is ordered. Should take 2 arguments to compare, and return a negative number, zero, or a positive number depending on whether the first argument is less than, equal to, or greater than the second.

Returns:

Array.<anychart.data.Tree.DataItem> - - Array of found tree data items.