Show / Hide Table of Contents

How to create a OrgChart JS programmatically

There are number of ways to create OrgChart JS programmatically

Using add function

Here is an example:

 
     
    chart.add({ id: 1, name: "Denny Curtis", title: "CEO" });
    chart.add({ id: 2, pid: 1, name: "Ashley Barnett", title: "Sales Manager" });
    chart.draw();
 

If you call draw function with OrgChart.action.init it will draw the chart based on scaleInitial and will center the graph

Using addNode function

If you add a node using addNode you will not need to call draw function

 
     
    chart.addNode({ id: 1, name: "Denny Curtis", title: "CEO" });
 

Using update function

 
     
    chart.update({ id: 4, pid: 2, name: "Updated Name", title: "Updated Title" });
    chart.update({ id: 1, name: "Updated Name", title: "Updated Title" });
    chart.draw();
 

Using updateNode function

 
     
    chart.updateNode({ id: 4, pid: 2, name: "Updated Name", title: "Updated Title" });
 

Using remove function

 
     
   chart.remove(2);
   chart.draw();
 

Using removeNode function

 
     
   chart.removeNode(2);