Open In App

Angular PrimeNG OrganizationChart Properties

Last Updated : 01 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG OrganizationChart Properties.

The OrganizationChart Component visualizes the data in hierarchical organizational data. The data is arranged in the tree format. The component provides a lot of properties, styling, events, templates, etc. which can be modified to create many variations.

Angular PrimeNG OrganizationChart Properties:

  • value: It is an array of nested TreeNodes. It is of null type & the default value is TreeNode[].
  • style: It is the inline style of the component. It is of string type & the default value is null.
  • styleClass: It is the style class of the component. It is of string type & the default value is null.
  • selectionMode: It defines the selection mode, valid values single and multiple. It is of string type & the default value is null.
  • selection: It is a single tree node instance or an array to refer to the selections. It accepts any type of d & the default value is null.
  • preserveSpace: It asks whether the space allocated by a node is preserved when hidden. It is of boolean type & the default value is true.

Syntax:

<p-organizationChart [value]="..."></p-organizationChart>

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save
npm install chart.js --save

Project Structure: It will look like the following:

 

  • Steps to run the application: Run the below command to see the output
ng serve --save

Example 1: Below is the example that illustrates the use of the Angular PrimeNG OrganizationChart Properties using the selectionMode property.

  • app.component.html:

HTML




<h1 style="color: green">
  GeeksforGeeks
</h1>
<h5>
      Angular PrimeNG OrganizationChart 
      Properties.
</h5>
  
<h4>Single Selection</h4>
<p-organizationChart [value]="gfg" 
                     selectionMode="single">
</p-organizationChart>
<hr>
<h4>Multiple Selection</h4>
<p-organizationChart [value]="gfg" 
                     selectionMode="multiple">
</p-organizationChart>


  • app.component.ts:

Javascript




import {Component} from '@angular/core';
import {TreeNode} from 'primeng/api';
import {MessageService} from 'primeng/api';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
    providers: [MessageService],
    styleUrls: ['./app.component.scss']
})
  
export class AppComponent {
    gfg: TreeNode[];
  
    constructor(private messageService: MessageService) {}
  
    ngOnInit() {
        this.gfg = [
            {
                label: 'Data Structures and Algorithms',
                expanded: true,
                children: [
                    {
                        label: 'Data Structures',
                        expanded: true,
                        children: [
                            {
                                label: 'Queue',
                            },
                            {
                                label: 'Red-Black Tree',
                            },
                        ],
                    },
                    {
                        label: 'Algorithms',
                        expanded: true,
                        children: [
                            {
                                label: 'Hashing',
                            },
                            {
                                label: 'Divide and Conquer',
                            },
                        ],
                    },
                ],
            },
        ];
    }
}


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { OrganizationChartModule }
    from 'primeng/organizationchart';
   
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        OrganizationChartModule,
        FormsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
   
export class AppModule { }


Output:

 

Example 2: Below is another example that illustrates the use of the Angular PrimeNG OrganizationChart Properties using the preserveSpace property.

  • app.component.html:

HTML




<h1 style="color: green">
  GeeksforGeeks
</h1>
<h5>
      Angular PrimeNG OrganizationChart 
      Properties.
</h5>
  
<h4>Preserve Space true</h4>
<p-organizationChart [value]="gfg"
                     [preserveSpace]="true">
</p-organizationChart>
<hr>
<h4>Preserve Space false</h4>
<p-organizationChart [value]="gfg"
                     [preserveSpace]="false">
</p-organizationChart>


  • app.component.ts:

Javascript




import {Component} from '@angular/core';
import {TreeNode} from 'primeng/api';
import {MessageService} from 'primeng/api';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
    providers: [MessageService],
    styleUrls: ['./app.component.scss']
})
  
export class AppComponent {
    gfg: TreeNode[];
  
    constructor(private messageService: MessageService) {}
  
    ngOnInit() {
        this.gfg = [
            {
                label: 'Data Structures and Algorithms',
                expanded: true,
                children: [
                    {
                        label: 'Data Structures',
                        expanded: true,
                        children: [
                            {
                                label: 'Queue',
                            },
                            {
                                label: 'Red-Black Tree',
                            },
                        ],
                    },
                    {
                        label: 'Algorithms',
                        expanded: true,
                        children: [
                            {
                                label: 'Hashing',
                            },
                            {
                                label: 'Divide and Conquer',
                            },
                        ],
                    },
                ],
            },
        ];
    }
}


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { OrganizationChartModule }
    from 'primeng/organizationchart';
   
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        OrganizationChartModule,
        FormsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
   
export class AppModule { }


Output:

 

Reference: https://primefaces.org/primeng/organizationchart



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads