Open In App

Angular PrimeNG Combo Chart Component

Last Updated : 25 Nov, 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. 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

Angular PrimeNG Polar Area Chart Component
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 Polar Area Chart Component in Angular PrimeNG. Polar area charts are similar to pie charts, but each segment has the
3 min read
Angular PrimeNG Pie Chart Component
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 Pie Chart Component in Angular PrimeNG. A Pie Chart is a circular statistical graphic, which is divided into slices t
3 min read
Angular PrimeNG Line Chart Component
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 are going to learn Angular Pri
4 min read
Angular PrimeNG Radar Chart Component
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 Radar Chart Component in Angular PrimeNG. A Radar Chart is a graphical method for rendering multivariate data that is
3 min read
How to Set Chart Title and Name of X Axis and Y Axis for a Chart in Chart.js ?
In this article, we will learn how to set the title, the name of the x-axis, and the name of the y-axis for a chart using the ChartJS CDN library. Approach:In the HTML template, use the &lt;canvas&gt; tag to show the line graph.In the script section of the code, instantiate the ChartJS object by setting the type, data, and options properties of the
3 min read
Angular PrimeNG Line Chart Line Styles
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 Line Chart Line Styles in Angular PrimeNG. A line chart or line graph is a type of chart that displays information as
3 min read
Angular PrimeNG Chart Complete Reference
Angular PrimeNG Chart Component facilitates the various chart designs that depict the data in different graphical representations. It is open open-source HTML5-based charting library. The complete list of Chart Components is listed below with their brief description: ChartModel ComponentThe ChartModel provides different types of properties that hel
4 min read
Angular PrimeNG ChartModel Chart Types
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 are going to learn Angular Pri
4 min read
Angular PrimeNG Line Chart Multi Axis
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. A line chart or line graph is a type of chart that displays information as a series of data points called 'markers' connected by straight line segment
4 min read
Angular PrimeNG Form Editor Component
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 how to use the Form Editor Component in Angular PrimeNG. The Form Editor is a Quill-based rich text editor component. The
3 min read