There are number of ways to create OrgChart JS programmatically
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(OrgChart.action.init);
If you call draw function with OrgChart.action.init it will draw the chart based on scaleInitial and will center the graph
If you add a node using addNode you will not need to call draw function
chart.addNode(n);
chart.update({ id: 4, pid: 2, name: "Updated Name", title: "Updated Title" }); chart.update({ id: 1, name: "Updated Name", title: "Updated Title" }); chart.draw();
chart.updateNode({ id: 4, pid: 2, name: "Updated Name", title: "Updated Title" });
chart.remove(2); chart.draw();
chart.removeNode(2);