Getting started with Angular 3D Circular Chart component

18 Mar 20246 minutes to read

This section explains you the steps required to create a simple Angular 3D Circular Chart and demonstrate the basic usage of the 3D Circular Chart component in an Angular environment.

Setup angular environment

You can use Angular CLI to setup your Angular applications.
To install Angular CLI use the following command.

npm install -g @angular/cli

Create an Angular application

Start a new Angular application using below Angular CLI command.

ng new my-app
cd my-app

Installing Syncfusion 3D Circular Chart package

Syncfusion packages are distributed in npm as @syncfusion scoped packages. You can get all the Angular Syncfusion package from npm link.

Currently, Syncfusion provides two types of package structures for Angular components,

  1. Ivy library distribution package format
  2. Angular compatibility compiler(Angular’s legacy compilation and rendering pipeline) package.

Ivy library distribution package

Syncfusion Angular packages(>=20.2.36) has been moved to the Ivy distribution to support the Angular Ivy rendering engine and the package are compatible with Angular version 12 and above. To download the package use the below command.

Add @syncfusion/ej2-angular-charts package to the application.

npm install @syncfusion/ej2-angular-charts --save

Angular compatibility compiled package(ngcc)

For Angular version below 12, you can use the legacy (ngcc) package of the Syncfusion Angular components. To download the ngcc package use the below.

Add @syncfusion/ej2-angular-charts@ngcc package to the application.

npm install @syncfusion/ej2-angular-charts@ngcc --save

To mention the ngcc package in the package.json file, add the suffix -ngcc with the package version as below.

@syncfusion/ej2-angular-charts:"20.2.38-ngcc"

Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning.

Registering 3D Circular Chart module

Import 3D Circular Chart module into Angular application(app.module.ts) from the package @syncfusion/ej2-angular-charts [src/app/app.module.ts].

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
// import the CircularChart3DAllModule for the 3D Circular Chart component
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts';
import { AppComponent }  from './app.component';

@NgModule({
  //declaration of CircularChart3DAllModule into NgModule
  imports:      [ BrowserModule, CircularChart3DAllModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }
  • Modify the template in app.component.ts file to render the ej2-angular-charts component
    [src/app/app.component.ts].
import { Component, ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'app-container',
  // specifies the template string for the 3D Circular Chart component
  template: `<ejs-circularchart3d id='chart-container'></ejs-circularchart3d>`,
  encapsulation: ViewEncapsulation.None
})
export class AppComponent  { }

Now use the app-container in the index.html instead of default one.

<app-container></app-container>
  • Now run the application in the browser using the below command.
npm start

Pie Series

By default pie series will be rendered on assigning JSON data to the series by using dataSource property. Map the field names in the JSON data to the xName and yName properties of the series.

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

@Component({
    selector: 'app-container',
    template: `<ejs-circularchart3d style='display:block;' align='center' tilt='-45' [title]='title' [legendSettings]="legendSettings">
    <e-circularchart3d-series-collection>
    <e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y' [dataLabel]='dataLabel'>
    </e-circularchart3d-series></e-circularchart3d-series-collection>
    </ejs-circularchart3d>`
})
export class AppComponent implements OnInit {
    public dataSource?: Object[];
    public title?: string;
    public legendSettings?: Object;
    public dataLabel?: Object;
    ngOnInit(): void {
        this.dataSource = [
            { x: 'Chrome', y: 62.92 },
            { x: 'Internet Explorer', y: 6.12 },
            { x: 'Opera', y: 3.15 },
            { x: 'Edge', y: 5.5 },
            { x: 'Safari', y: 19.97 },
            { x: 'Others', y: 2.34 }];
        this.title = 'Browser Market Shares in November 2023';
        this.legendSettings = { visible: true, position: 'Right' };
        this.dataLabel = {
            visible: true,
            name: 'x',
            position: 'Outside',
            font: {
                fontWeight: '600'
            },
            connectorStyle: { length: '40px' }
        };
    }
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule, CircularChart3DAllModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [CircularChart3DAllModule]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

import 'zone.js';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);