AnyChart
API Reference
Still have questions?
Contact support
Top

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 the index of child in a children array.
numChildren()Returns a length of roots array.
removeChild()Removes data item's child.
removeChildAt()Removes child at the specified position.
removeChildren()Removes children.
search()Performs a data search.
searchItems()Performs an items search and returns an array of data items.
Miscellaneous
filter()Filters the tree data items using the filter-function.

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

filter

Filters the tree data items using the filter-function.

Params:

NameTypeDescription
filterFunctionfunction(item:anychart.data.Tree.DataItem|anychart.data.TreeView.DataItem)Filter function.

Returns:

Array.<(anychart.data.Tree.DataItem|anychart.data.TreeView.DataItem)> - An array of data items.

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|string.TREE);
var mapping = treeData.mapAs({"name": "id"};
// Creates traverser
mapping.getTraverser();

indexOfChild

Gets the 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 the 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 search.
Learn more about searching.

Params:

NameTypeDescription
fieldstringSearch field name.
value*Value to be found.
comparisonFnfunction(value1:*, value2:*)An optional comparison function by which the array is ordered. Should take 2 arguments to compare and return a negative number, zero, or positive number depending on whether the first argument is less than, equal to or greater than the second.

Returns:

Array.<anychart.data.Tree.DataItem> - An array of found tree data items. If nothing is found, the array is returned empty.