How to Create Organizational Chart by JSON Data in JavaScript Diagram?
Syncfusion® JavaScript Diagram provides built-in support for auto-arranging nodes into various layout types. One of the most commonly used layouts is the Organizational Chart, which visually represents the structure of an organization, highlighting relationships between different entities. This article demonstrates how to create an organizational chart using JSON data.
Steps to Create an Organizational Chart from JSON Data
1. Import JSON Data:
To begin, import the JSON file that contains the data for your organizational chart.
// Import the JSON data
import * as data from './datasource.json';
2. Configure the Diagram Component
After importing the JSON data, the next step is to configure the diagram component. You need to bind the data to the diagram using the dataSourceSettings property. The id and parentId fields define the hierarchical relationship between the nodes, and the dataSource binds the actual data. Additionally, the layout property is used to set the layout type for the diagram.
//Initializes the diagram component
var diagram = new ej.diagrams.Diagram({
width: '100%', height: '800px',
//configures data source settings
dataSourceSettings: {
id: 'Id', parentId: 'Team',
dataSource: new ej.data.DataManager(data.OrgChartData) //JSON data
},
//Configure the layout type
layout: {
type: 'OrganizationalChart',
}
});
diagram.appendTo('#diagram');
You can find a working example of this implementation on StackBlitz in the provided link: Click here for sample
Conclusion
I hope you enjoyed learning how to create Organizational chart by JSON data in JavaScript Diagram.
You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!