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.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:

NameTypeDescription
childObject | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItemChild to set.

Returns:

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

addChildAt

Inserts a child into a specified position.

Params:

NameTypeDescription
childObject | anychart.data.Tree.DataItem | anychart.data.TreeView.DataItemChild to set.
indexnumberPosition.

Returns:

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

addData

Adds a data.

Params:

NameTypeDescription
dataArray.<Object> | stringRaw data or CSV-string. If string is passed, second parameter will be interpreted as fields mapping.
fillMethodOrCsvMappinganychart.enums.TreeFillingMethod | ObjectFill 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 }; .
csvSettingsOrDepsObject | 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.

getChildAt

Gets the child by index.

Params:

NameTypeDescription
indexnumberIndex of child to find.

Returns:

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

getChildren

Returns a roots array.

Returns:

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

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:

NameTypeDescription
childanychart.data.Tree.DataItem | anychart.data.TreeView.DataItemChild for getting of index.

Returns:

number - Index of child.

numChildren

Returns a length of roots array.

Returns:

number - Number of roots.

removeChild

Removes data item's child.

Params:

NameTypeDescription
childanychart.data.Tree.DataItem | anychart.data.TreeView.DataItemChild for removal..

Returns:

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

removeChildAt

Removes child at specified position.

Params:

NameTypeDescription
indexnumberIndex of item to be removed.

Returns:

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

removeChildren

Removes children.

Returns:

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

searchItems

Performs a data item search.

Params:

NameTypeDescription
soughtFieldstringField for search. Literally means the name of field of data item.
valuestring | number | booleanSought value.
comparisonFnfunction | ObjectCustom comparison function.

Returns:

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