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

class anychart.data.TreeView Improve this Doc

Extends: anychart.core.Base

TreeView. Class of mapped tree.

Methods Overview

Data
addChild()Adds a child.
addChildAt()Inserts a child into a specified position.
addData()Adds a data.
getChildAt()Gets the child by index.
getChildren()Returns a roots array.
getTraverser()Creates tree view data traverser.
indexOfChild()Gets index of child in a children array.
numChildren()Returns a length of roots array.
removeChild()Removes data item's child.
removeChildAt()Removes child at specified position.
removeChildren()Removes children.
search()Performs a data search.
searchItems()Performs a items search.

Methods Description

addChild

Adds a child.

Params:

Name Type Description
child Object | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem Child to set.

Returns:

anychart.data.TreeView.DataItem - An instance of the class for method chaining.

Try it:

addChildAt

Inserts a child into a specified position.

Params:

Name Type Description
child Object | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem Child to set.
index number Position.

Returns:

anychart.data.TreeView.DataItem - An instance of the class for method chaining.

Try it:

addData

Adds a data.

Params:

Name Type Description
data Array.<Object> | string Raw data or CSV-string. If string is passed, second parameter will be interpreted as fields mapping.
fillMethodOrCsvMapping anychart.enums.TreeFillingMethod | Object Fill method or CSV mapping object. This parameter is interpreted as mapping object if first parameter is string. Mapping object should have structure like //'nameOfField': index_of_column mapping = { 'id': 0, 'name': 1, 'value': 15 }; .
csvSettingsOrDeps Object | Array.<anychart.data.Tree.Dependency> CSV settings object or dependencies data. If is CSV settings object, should fields like rowsSeparator - string or undefined, if it is undefined, it will not be set. columnsSeparator - string or undefined, if it is undefined, it will not be set. ignoreTrailingSpaces - boolean or undefined, if it is undefined, it will not be set. ignoreFirstRow - boolean or undefined, if it is undefined, it will not be set.
If is dependencies data, should take an array like this: var dependencies = [ {from: 0, to: 3}, //ids {from: 0, to: 4}, {from: 1, to: 2}, {from: 4, to: 5} ];

Returns:

anychart.data.TreeView - Self instance for method chaining.

Try it:

getChildAt

Gets the child by index.

Params:

Name Type Description
index number Index of child to find.

Returns:

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

Try it:

getChildren

Returns a roots array.

Returns:

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

Try it:

getTraverser

Creates tree view data traverser.

Returns:

anychart.data.Traverser - An instance of the class for method chaining.
See listing.
var rawdata = [
{id: 1, children: [
    {id: 2, children: [
        {id: 3},
        {id: 4, children: [
            {id: 5},
            {id: 6}
        ]}
    ]},
    {id: 7, children: [
        {id: 8}
    ]}
]}
];
var treeData = anychart.data.tree(rawdata, anychart.enums.TreeFillingMethod.TREE);
var mapping = treeData.mapAs({"name": "id"};
// Creates traverser
mapping.getTraverser();

indexOfChild

Gets index of child in a children array.

Params:

Name Type Description
child anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem Child for getting of index.

Returns:

number - Index of child.

Try it:

numChildren

Returns a length of roots array.

Returns:

number - Number of roots.

Try it:

removeChild

Removes data item's child.

Params:

Name Type Description
child anychart.data.Tree.DataItem | anychart.data.TreeView.DataItem Child for removal..

Returns:

anychart.data.TreeView.DataItem - An instance of the class for method chaining.

Try it:

removeChildAt

Removes child at specified position.

Params:

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

Returns:

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

Try it:

removeChildren

Removes children.

Returns:

anychart.data.TreeView - Self instance for method chaining.

Try it:

searchItems

Performs a data item search.

Params:

Name Type Description
soughtField string Field for search. Literally means the name of field of data item.
value string | number | boolean Sought value.
comparisonFn function | Object Custom comparison function.

Returns:

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

Try it: