Articles in this section
Category / Section

How to Create Hierarchical Tree with HTML Code in Vue Diagram?

3 mins read

HTML content can be added in the Vue Diagram through an HTML type node. The shape property of the node allows you to set the type of node, and to create an HTML node, it should be set as “HTML”.

Diagram provides support to create a Hierarchical tree layout, which is used to arrange nodes automatically based on a predefined layout logic.

Create Hierarchical tree layout in diagram

  1. To generate a layout from DataSource, you have to define the business object and add the necessary data to the DataSource collection. During the layout generation, nodes and connectors can be generated automatically with the information provided through the data source, and those items will be added to NodeCollection and ConnectorCollection respectively.
  2. To arrange the nodes in a hierarchical structure, specify the layout type as HierarchicalTree.
data: function () {
   return {
     width: '100%',
     height: '700px',
     snapSettings: { constraints: SnapConstraints.None },
     nodeTemplate: function () {
       return {
         template: createApp({}).component('nodeTemplate', NodeTemplate),
       };
     },
     created: function () {
       var diagramInstance =
         document.getElementById('diagram').ej2_instances[0];
       diagramInstance.dataSourceSettings = {
         id: 'Id',
         parentId: 'Manager',
         dataSource: new DataManager(localBindData),
       };
       //Configures automatic layout
       diagramInstance.layout = {
         type: 'HierarchicalTree',
       };
     },

     //Defines the default node and connector properties
     getNodeDefaults: (obj, diagram) => {
       return nodeDefaults(obj, diagram);
     },
     getConnectorDefaults: (connector, diagram) => {
       return connectorDefaults(connector, diagram);
     },
   };
 }, 
Create the Hierarchical layout with HTML Node
  1. To create an HTML node, you should set the type of node shape to HTML.
  2. To add HTML code, define the HTML code in the nodeTemplate.
function nodeDefaults(obj, diagram) {
 obj.shape ={type:'HTML'}
 obj.backgroundColor = '#6BA5D7'
 obj.width = 80;
 obj.height = 80;
 return obj;
} 
<template>
 <div
   :style="{
     background: data.color,
     height: '100%',
     width: '100%',
     position: 'absolute',
   }"
 >
   <div>
     <p class="myTitle">{{ data.data.Role }}</p>
   </div>
 </div>
</template> 
```

Sample: Click Here

Conclusion

I hope you enjoyed learning how to create Hierarchical tree with HTML code in Vue Diagram.

You can refer to our Vue 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 Vue 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!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied