Create an Organization Chart Using Open API
Organization chart is a useful tool for showing an organization’s structure, indicating its parts and positions’ relationships and ranks. This article will demonstrate how to create an organizational chart using Open API.
Create a Blank Organizational Chart
We can first use the method DiagramManager.createDiagram to create a blank diagram.
//Create Blank Diagram DiagramManager diagramManager = ApplicationManager.instance().getDiagramManager(); IDiagramUIModel org = (IDiagramUIModel) diagramManager.createDiagram(IDiagramTypeConstants.DIAGRAM_TYPE_ORGANIZATION_CHART); org.setName("Simple Organization Chart");
Create Units
We can use IModelElementFactory to create units once the diagram is created.
//Create Unit IOCUnit projectManager = IModelElementFactory.instance().createOCUnit(); projectManager.setName("Project Manager"); IOCUnitUIModel shapeProjectManager = (IOCUnitUIModel) diagramManager.createDiagramElement(org, projectManager); shapeProjectManager.setBounds(400, 50, 150, 50); shapeProjectManager.resetCaption();
For better categorization, you may use the method IOCUnitModel.getFillColor().setColor1(Color c) to customize the color of each block.
//Set up the color for the unit(Optional) shapeSystemEng.getFillColor().setColor1(new Color(128, 128, 255));
Create Connectors
When all unit are created, we can then create the connector between them.
//create Connector IOCLine proManToDeptMan = IModelElementFactory.instance().createOCLine(); proManToDeptMan.setFrom(projectManager); proManToDeptMan.setTo(deptProjectManager); diagramManager.createConnector(org, proManToDeptMan, shapeProjectManager, shapeDeptProjectManager, new Point[] {});
Show Up the Diagram
Finally, we can show up the diagram
//show up diagram diagramManager.openDiagram(org);
Sample Plugin
The sample plugin demonstrate how to create organization chart using Open API. After you deploy the plugin into Visual Paradigm you can then click the plugin button in the application toolbar to trigger it.
Download Sample Plugin
You can click this link to download the sample plugin.
Related Know-how |
Related Link |
Leave a Reply
Want to join the discussion?Feel free to contribute!