# Charts: TreeViewer

**URL:** <https://community.datagrok.ai/t/charts-treeviewer/658>\
**Category:** Features\
**Tags:** vis\
**Created:** [July 7, 2022, 9:59am UTC](https://community.datagrok.ai/t/charts-treeviewer/658 "2022-07-07T09:59:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![donufriienko](https://community.datagrok.ai/user_avatar/community.datagrok.ai/donufriienko/32/87_2.png) [@donufriienko](https://community.datagrok.ai/u/donufriienko)\
**Post date:** [July 7, 2022, 9:59am UTC](https://community.datagrok.ai/t/charts-treeviewer/658/1 "2022-07-07T09:59:57Z")

</div>

`TreeViewer` is used to visualize hierarchical data. The chart builds a tree structure with up to three levels for a given dataset. The columns are selected based on a number of categories in them. To change the order of columns, add new levels to the initial hierarchy or remove the existing ones, edit the `hierarchy` property.

 ![tree-viewer](https://community.datagrok.ai/uploads/default/original/1X/5d6700f41873b127e2b70ed1d44eb329abdbab71.gif)

The chart responds to data filters and rows selection. The only difference with the native viewers behavior is that the selection of rows in `TreeViewer` has limited interaction. The selection works on clicks with applied modifier keys (`Shift` adds to the selection, `Ctrl` toggles the selected state, see more in the [wiki](https://datagrok.ai/help/visualize/viewers#selection)); while a regular click on a node is reserved for expanding or collapsing branches of the tree.

In the viewer properties, you can adjust marker settings, change a tree layout, or toggle certain behaviors, such as animation, expanding or collapsing nodes, etc.

Package: [Charts v1.0.0](https://www.npmjs.com/package/@datagrok/charts/v/1.0.0)  
Documentation: [TreeViewer](https://github.com/datagrok-ai/public/tree/master/packages/Charts#treeviewer)  
Demo dataset: [demographics](https://dev.datagrok.ai/f/Demo.Files/demog.csv)

---

<div class="post-metadata">

**Author:** ![skalkin](https://community.datagrok.ai/user_avatar/community.datagrok.ai/skalkin/32/5_2.png) [@skalkin](https://community.datagrok.ai/u/skalkin)\
**Post date:** [July 8, 2022, 1:45am UTC](https://community.datagrok.ai/t/charts-treeviewer/658/2 "2022-07-08T01:45:28Z")

</div>

This is fantastic, and I see so many use cases for it! Would it also be possible to add size-coding by number of rows that belong to a node?

---

<div class="post-metadata">

**Author:** ![donufriienko](https://community.datagrok.ai/user_avatar/community.datagrok.ai/donufriienko/32/87_2.png) [@donufriienko](https://community.datagrok.ai/u/donufriienko)\
**Post date:** [July 8, 2022, 6:59am UTC](https://community.datagrok.ai/t/charts-treeviewer/658/3 "2022-07-08T06:59:55Z")

</div>

The size-coding feature is on its way, so yes, this will be available soon.

---

<div class="post-metadata">

**Author:** ![donufriienko](https://community.datagrok.ai/user_avatar/community.datagrok.ai/donufriienko/32/87_2.png) [@donufriienko](https://community.datagrok.ai/u/donufriienko)\
**Post date:** [July 19, 2022, 7:47pm UTC](https://community.datagrok.ai/t/charts-treeviewer/658/4 "2022-07-19T19:47:28Z")

</div>

_Charts v1.0.1 Updates_

- _TreeViewer_: size-coding support (based on the `Size` column and an aggregation function specified in `Size Aggr Type`).  
 ![image](https://community.datagrok.ai/uploads/default/original/1X/e1d70723ed635839d5af6dafa2be5f5e443a78ee.png)
- _TreeViewer_: the `Initial Tree Depth` option has been added to adjust the number of expanded levels. The default depth is `2` (`level 0` is the root node, `level 1` contains the root’s children, and so on, `-1` expands all the nodes).

---

<div class="post-metadata">

**Author:** ![skalkin](https://community.datagrok.ai/user_avatar/community.datagrok.ai/skalkin/32/5_2.png) [@skalkin](https://community.datagrok.ai/u/skalkin)\
**Post date:** [July 19, 2022, 8:14pm UTC](https://community.datagrok.ai/t/charts-treeviewer/658/5 "2022-07-19T20:14:44Z")

</div>

Looks great!

> The chart builds a tree structure with up to three levels for a given dataset

I wonder why are we restricting it to three levels only?

---

<div class="post-metadata">

**Author:** ![donufriienko](https://community.datagrok.ai/user_avatar/community.datagrok.ai/donufriienko/32/87_2.png) [@donufriienko](https://community.datagrok.ai/u/donufriienko)\
**Post date:** [July 20, 2022, 6:54am UTC](https://community.datagrok.ai/t/charts-treeviewer/658/6 "2022-07-20T06:54:24Z")

</div>

It’s the initial tree depth, we aren’t restricting the number of levels (the `hierarchy` property provides for that, it’s stated above about adding/removing levels). So, if we add a viewer via the user interface, the chart will pick up to three categorical columns; if we add it programmatically with, say, five columns (or change `hierarchy` in the existing viewer to such values), it will expand the first three levels, but the tree leaves will be hidden, as the last two levels are collapsed. There’s also an initial depth parameter, which can be used as a shortcut to immediately expand the whole tree (value -1) or collapse it after a certain level (0 corresponds to the root, 1 to the next level, and so on).
