Overview
TheTree class displays a hierarchical tree diagram with nodes connected by links. It extends LinkedHierarchy and uses the D3 tree layout algorithm to position nodes.
Class Hierarchy
- Series
- Hierarchy
- LinkedHierarchy
- Tree
- LinkedHierarchy
- Hierarchy
Settings
orientation
Orientation of the diagram.
"vertical"- Tree grows from top to bottom"horizontal"- Tree grows from left to right
inversed
If set to
true, will flip the tree direction.For vertical orientation, this flips top-to-bottom to bottom-to-top.
For horizontal orientation, this flips left-to-right to right-to-left.Since: 5.2.4Inherited Settings
Tree inherits all settings from LinkedHierarchy and Hierarchy, including:sort- How to sort nodes by value (“ascending” | “descending” | “none”)valueField- Field in data holding numeric valuecategoryField- Field in data holding category namechildDataField- Field in data holding array of childrendownDepth- Number of child levels to show when drilling downupDepth- Number of parent levels to show from selected nodeinitialDepth- Number of levels to show on first loadtopDepth- Starting level to show (hides upper levels)singleBranchOnly- Collapse other branches when one expandsanimationDuration- Duration for drill animations in millisecondsanimationEasing- Easing function for animationscolors- ColorSet for auto-assigning node colorspatterns- PatternSet for auto-assigning node patternslinkWithField- Field holding IDs of nodes to link with
Data Item Properties
Each data item in a Tree chart has the following properties:children
An array of children data items.
parent
Parent data item.
value
Value of the node as set in data.
sum
Sum of child values.
valuePercentTotal
Percent value of the node, based on total sum of all nodes in upper level.
valuePercent
Percent value of the node, based on the value of its direct parent.Since: 5.2.21
category
Category name of the node.
depth
Node’s depth within the hierarchy (0 for root).
node
Reference to the visual LinkedHierarchyNode element.
circle
Circle element of the node.
outerCircle
Outer circle element of the node (shown for nodes with children).
label
Reference to node’s Label element.
fill
Node’s auto-assigned color.
fillPattern
Node’s auto-assigned pattern.Since: 5.10.0
disabled
Indicates if node is currently disabled (collapsed).
parentLink
HierarchyLink leading to parent node.
childLinks
Array of HierarchyLink objects leading to child nodes.
linkWith
Array of IDs of directly linked nodes (for custom cross-links).
Data Format
Example Data
List Templates
Tree provides access to these list templates for customization:nodes
List of all node elements. Use to customize node appearance and behavior.
circles
List of node circle elements. Use to customize circle appearance.
outerCircles
List of node outer circle elements (shown for nodes with children).
labels
List of label elements.
links
List of link elements connecting nodes.
Containers
nodesContainer
Container that holds all node elements.
linksContainer
Container that holds all link elements.
Methods
selectDataItem()
The data item to select.
getDataItemById()
The ID to search for.
The found data item, or undefined if not found.
linkDataItems()
Source node data item.
Target node data item.
Optional link strength.
The created or existing link element.
unlinkDataItems()
Source node data item.
Target node data item.
areLinked()
true if two nodes are linked with each other.
Source node data item.
Target node data item.
True if nodes are linked, false otherwise.
enableDataItem()
Target data item to enable.
Maximum depth to enable children to.
Current depth (used internally for recursion).
Animation duration in milliseconds.
disableDataItem()
Target data item to disable.
Animation duration in milliseconds.
addChildData()
Parent data item to add children to.
Array of child data objects.
hoverDataItem()
Target data item.
unhoverDataItem()
Target data item.
Events
dataitemselected
The selected data item.
Private Settings
These are read-only private settings managed internally:scaleX
Current horizontal scale.
scaleY
Current vertical scale.