Open In App

Angular PrimeNG Combo Chart Component

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
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. In this article, we will see the Angular PrimeNG Combo Chart Component.

The Combo Chart Component provides various kinds of charts that can be combined in the same graph, in order to visualize the different datasets at a moment.

Syntax:

<p-chart type="bar" 
         [data]="data" 
         [options]="chartOptions">
</p-chart>

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: The project structure will look like the following:

 

Example 1: This example describes the basic usage of the Combo Chart Component in Angular PrimeNG, where we will combine a bar chart and a line chart.

  • app.component.html
HTML
<div id="GFG">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>Angular PrimeNG Combo Chart </h2>
    <div style="width:30%;">
        <p-chart type="bar" 
                 [data]="data" 
                 [options]="chartOptions">
        </p-chart>
    </div>
</div>
  • app.component.ts
HTML
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    title = 'GFG';
    data = {
        labels: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
        datasets: [{
            type: 'line',
            label: 'City',
            borderColor: 'red',
            borderWidth: 2,
            fill: false,
            data: [49, 24, 22, 38, 26, 46, 54]
        },
        {
            type: 'bar',
            label: 'States',
            backgroundColor: '#66BB6A',
            data: [31, 74, 34, 65, 47, 45, 75],
            borderColor: 'white',
            borderWidth: 2
        }]
    };

    chartOptions = {
        plugins: {
            legend: {
                labels: {
                    color: 'black'
                }
            }
        },
        scales: {
            x: {
                ticks: {
                    color: 'black'
                },
                grid: {
                    color: 'grey'
                }
            },
            y: {
                ticks: {
                    color: 'black'
                },
                grid: {
                    color: 'grey'
                }
            }
        }
    };
}
  • app.module.ts
JavaScript
import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { AppComponent } from './app.component';
import {ChartModule} from 'primeng/chart';

@NgModule({
  declarations: [
    AppComponent,
    
  ],
  imports: [
    BrowserModule,
    ChartModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Output

 

Example 2:  This is another example that describes the use of the Combo Chart Component in Angular PrimeNG, where we will combine a radar chart and a line chart.

  • app.component.html
HTML
<div id="GFG">
    <h1 style="color:green">
            GeeksforGeeks
    </h1>
    <h2>Angular PrimeNG Combo Chart </h2>
    <div style="width:60%;">
        <p-chart type="bar" 
                 [data]="data" 
                 [options]="chartOptions">
        </p-chart>
    </div>
</div>
  • app.component.ts
JavaScript
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    title = 'GFG';
    data = {
        labels: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
        datasets: [{
            type: 'line',
            label: 'City ',
            borderColor: 'pink',
            borderWidth: 2,
            fill: false,
            data: [48, 27, 22, 38, 66, 66, 44]
        },
        {
            type: 'radar',
            label: 'State',
            backgroundColor: 'purple',
            data: [25, 74, 34, 65, 47, 65, 55],
            borderColor: 'white',
            borderWidth: 2
        }]
    };

    chartOptions = {
        plugins: {
            legend: {
                labels: {
                    color: 'blue'
                }
            }
        },
        scales: {
            x: {
                ticks: {
                    color: 'blue'
                },
                grid: {
                    color: 'grey'
                }
            },
            y: {
                ticks: {
                    color: 'blue'
                },
                grid: {
                    color: 'grey'
                }
            }
        }
    };
}
  • app.module.ts
HTML
import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { ChartModule } from 'primeng/chart';

@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        BrowserModule,
        ChartModule
    ],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }

Output:

 

Reference: http://primefaces.org/primeng/chart/combo


Similar Reads