Tree and TreeItem

This simple example will show you to make a multilevel tree map using Google Apps Script.

Reference:

Example Demo:

To try the demo, click on tree items

Example Code:

/*

tree Map

-------------------------------

Item0

     Item00

          Item000

          Item001

               Item0010

               Item0011

          Item002

    Item01

Item1

--------------------------------

*/

function doGet(e) {

  var app = UiApp.createApplication();

  //Create a tree

  var tree = app.createTree().setAnimationEnabled(true);

  

  //Create Top lavel Items

  var item0 = app.createTreeItem('Item0');

  var item1 = app.createTreeItem('Item1');

  

  //Create second level Items for item0

  var item00 = app.createTreeItem('Item00');

  var item01 = app.createTreeItem('Item01');

  item0.addItem(item00).addItem(item01);

  

  //Create third level Items

  var item000 = app.createTreeItem('Item000');

  var item001 = app.createTreeItem('ITem001');

  var item002 = app.createTreeItem('Item002');

  item00.addItem(item000).addItem(item001).addItem(item002);

  

  //Create Fourth level Item

  var item0010 = app.createTreeItem('Item0010');

  var item0011 = app.createTreeItem('Item0011');

  item001.addItem(item0010).addItem(item0011);

  

  //Add the top level items to tree

  tree.addItem(item0)

    .addItem(item1);

  

  app.add(tree);

  return app;

  

}

Keyword:

Tree, TreeItem in Google Apps Script, Create multilevel tree using Apps Script