Angular 11 Radar Chart using ng2-charts Example

By Hardik Savani November 5, 2023 Category : Angular

This article will give you example of angular 11 radar chart example. we will help you to give example of angular 11 radar chart npm. this example will help you angular 11 ng2-charts radar chart . i would like to share with you how to add radar chart in angular 11.

In this example we will use ng2-charts npm package to create radar chart example in angular 11 application. we will simply install that ng2-charts npm package and use ChartsModule module to create code.

So, let's see bellow step and get qr code as like bellow screenshot:

Preview:

Step 1: Create New App

You can easily create your angular app using bellow command:

ng new myNewApp

Step 2: Install ng2-charts npm Package

Now in this step, we need to just install ng2-charts in our angular application. so let's add as like bellow:

npm install ng2-charts chart.js --save

Step 3: Import ChartsModule

we will import ChartsModule module as like bellow code:

src/app/app.module.ts

import { NgModule } from '@angular/core';

import { BrowserModule } from '@angular/platform-browser';

import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';

import { ChartsModule } from 'ng2-charts';

@NgModule({

imports: [ BrowserModule, FormsModule, ChartsModule ],

declarations: [ AppComponent ],

bootstrap: [ AppComponent ]

})

export class AppModule { }

Step 4: Update Ts File

here, we need to update ts file as like bellow:

src/app/app.component.ts

import { Component, OnInit } from '@angular/core';

import { ChartDataSets, ChartType, RadialChartOptions } from 'chart.js';

import { Label } from 'ng2-charts';

@Component({

selector: 'my-app',

templateUrl: './app.component.html',

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

public radarChartOptions: RadialChartOptions = {

responsive: true,

};

public radarChartLabels: Label[] = ['PHP', '.Net', 'Java', 'Android', 'Node.JS'];

public radarChartData: ChartDataSets[] = [

{ data: [62, 59, 80, 81, 56], label: 'Uses' },

{ data: [30, 48, 50, 29, 80], label: 'Popular' }

];

public radarChartType: ChartType = 'radar';

constructor() { }

ngOnInit() {

}

}

Step 5: Update HTML File

here, we need to update html file as like bellow code:

src/app/app.component.html

<h1>Angular radar chart example - ItSolutionStuff.com</h1>

<div style="display: block;">

<canvas baseChart

[datasets]="radarChartData"

[options]="radarChartOptions"

[labels]="radarChartLabels"

[chartType]="radarChartType">

</canvas>

</div>

Now you can run by bellow command:

ng serve

now you can check it.

I hope it can help you...

Shares