Create Organization Chart in VSS in Java
Native and high performance create organization chart in VSS document using server-side Aspose.Diagram for Java APIs, without the use of any software like Microsoft or Open Office, Adobe PDF.
How to Create Organization Chart in VSS File Using Java
In order to create organization chart in VSS file, we’ll use
API which is a feature-rich, powerful and easy to use merger API for Java platform. You can download its latest version directly from
and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-diagram</artifactId>
<version>version of aspose-diagram API</version>
<classifier>jdk17</classifier>
</dependency>
Steps for Create Organization Chart in VSS Files in Java
Creating organization chart with
APIs can be done with just few lines of code.
- Create a diagram from stencil.
- Select Page via its id
- Add organization node shapes to page.
- Add connectors to page to connect shape and its parent.
- Auto layout by invoking layout mothod
- Call the save() method and pass the file name (full path) and format (VSDX) as a parameter.
- Now you can open and use the VSDX file in Microsoft Office, Adobe PDF or any other compatible program.
System Requirements
Aspose.Diagram for Java supports on all major platforms and Operating Systems. Please make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.Diagram for Java directly from Maven .
Create Organization Chart in VSS Files - Java
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DrawCompactTreeChart.class); | |
// Load masters from any existing diagram, stencil or template | |
// And add in the new diagram | |
String visioStencil = dataDir + "Basic Shapes.vss"; | |
String rectangleMaster = "Rectangle"; | |
String connectorMaster = "Dynamic connector"; | |
int pageNumber = 0; | |
double width = 1; | |
double height = 1; | |
double pinX = 4.25; | |
double pinY = 9.5; | |
// Define values to construct the hierarchy | |
List<String> listPos = Arrays.asList(new String[] { "0", "0:0", "0:1", "0:2", "0:3", "0:4", "0:5", "0:6", "0:0:0", "0:0:1", "0:3:0", "0:3:1", "0:3:2", "0:6:0", "0:6:1" }); | |
// Define a Hashtable to map the string name to long shape id | |
Hashtable shapeIdMap = new Hashtable(); | |
// Create a new diagram | |
Diagram diagram = new Diagram(visioStencil); | |
diagram.getPages().get(pageNumber).getPageSheet().getPageProps().getPageWidth().setValue(11); | |
for (String orgnode : listPos) | |
{ | |
// Add a new rectangle shape | |
long rectangleId = diagram.addShape(pinX++, pinY++, width, height, rectangleMaster, pageNumber); | |
// Set the new shape's properties | |
Shape shape = diagram.getPages().get(pageNumber).getShapes().getShape(rectangleId); | |
shape.getText().getValue().add(new Txt(orgnode)); | |
shape.setName(orgnode); | |
shapeIdMap.put(orgnode, rectangleId); | |
} | |
// Create connections between nodes | |
for (String orgName : listPos) | |
{ | |
int lastColon = orgName.lastIndexOf(':'); | |
if(lastColon > 0) | |
{ | |
String parendName = orgName.substring(0, lastColon); | |
long shapeId = (long)shapeIdMap.get(orgName); | |
long parentId = (long)shapeIdMap.get(parendName); | |
Shape connector1 = new Shape(); | |
long connecter1Id = diagram.addShape(connector1, connectorMaster, pageNumber); | |
diagram.getPages().get(pageNumber).connectShapesViaConnector(parentId, ConnectionPointPlace.RIGHT, | |
shapeId, ConnectionPointPlace.LEFT, connecter1Id); | |
} | |
} | |
//auto layout CompactTree chart | |
LayoutOptions compactTreeOptions = new LayoutOptions(); | |
compactTreeOptions.setLayoutStyle(LayoutStyle.COMPACT_TREE); | |
compactTreeOptions.setDirection(LayoutDirection.DOWN_THEN_RIGHT); | |
compactTreeOptions.setEnlargePage(false); | |
diagram.getPages().get(pageNumber).layout(compactTreeOptions); | |
// Save diagram | |
diagram.save(dataDir + "DrawCompactTreeChart_java.vsdx", SaveFileFormat.VSDX); |
About Aspose.Diagram for Java API
Aspose.Diagram is a Microsoft Visio document format manipulation API. One can easily load, create, modify, manipulate including daigram elements and convert Visio diagrams to other formats such as PDF, XPS, JPEG, PNG, BMP, TIFF, SVG, EMF and more. It is a standalone API and does not require Microsoft Visio or any other software to be installed.Online VSS CompactTree Style Organization Chart Live Demos
Create CompactTree Style Organization Chart in VSS documents right now by visiting our Live Demos website . The live demo has the following benefits
VSS What is VSS File Format?
VSS are stencil files created with Microsoft Visio 2007 and earlier. A relatively new file format is .VSSX that was introduced with Microsoft Visio 2013. Stencil files provide drawing objects that can be included in a .VSD Visio drawing. Microsoft Visio itself is known for creating drawing elements such as collection of shapes, connectors, flowcharts, network layout, UML diagrams, software diagrams, database models, objects mapping and other similar information. It also has rich conversion features of Visio documents to other file formats such as PNG, BMP, PDF and others. Visio is available for both Windows and Mac OS.
Read MoreOther Supported Organization Chart Formats
Using Java, one can easily create CompactTree style organization chart in different formats including.