Pie and donut in Angular 3D Circular Chart component

13 May 202419 minutes to read

Pie chart

To render a pie series, inject the PieSeries3DService module into the @NgModule.providers.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'

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

@Component({
imports: [
         CircularChart3DAllModule
    ],

providers: [CircularChart3DAllModule],
standalone: true,
    selector: 'app-container',
    template: `<ejs-circularchart3d style='display:block;' align='center' [tilt]='tilt' [legendSettings]="legendSettings">
    <e-circularchart3d-series-collection>
    <e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y'>
    </e-circularchart3d-series></e-circularchart3d-series-collection>
    </ejs-circularchart3d>`
})
export class AppComponent implements OnInit {
    public dataSource?: Object[];
    public title?: string;
    public legendSettings?: Object;
    public tilt?: number;
    ngOnInit(): void {
        this.dataSource = [
          { x: 'Jan', y: 3 },  { x: 'Feb', y: 3.5 }, 
          { x: 'Mar', y: 7 },  { x: 'Apr', y: 13.5 },
          { x: 'May', y: 19 }, { x: 'Jun', y: 23.5 }, 
          { x: 'Jul', y: 26 }, { x: 'Aug', y: 25 },
          { x: 'Sep', y: 21 }, { x: 'Oct', y: 15 }
        ];
        this.legendSettings = { visible: false };
        this.tilt= -45
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Radius customization

By default, the radius of the pie series will be 80% of the size, which is the minimum of the 3D Circular Chart’s width and height. You can customize this by using the radius property of the series.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'

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

@Component({
imports: [
         CircularChart3DAllModule
    ],

providers: [CircularChart3DAllModule],
standalone: true,
    selector: 'app-container',
    template: `<ejs-circularchart3d style='display:block;' align='center' [tilt]='tilt' [legendSettings]="legendSettings">
    <e-circularchart3d-series-collection>
    <e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y' [radius]='radius'>
    </e-circularchart3d-series></e-circularchart3d-series-collection>
    </ejs-circularchart3d>`
})
export class AppComponent implements OnInit {
    public dataSource?: Object[];
    public title?: string;
    public legendSettings?: Object;
    public tilt?: number;
    public radius?: string;
    ngOnInit(): void {
        this.dataSource = [
            { x: 'Jan', y: 3 }, { x: 'Feb', y: 3.5 },
            { x: 'Mar', y: 7 }, { x: 'Apr', y: 13.5 },
            { x: 'May', y: 19 }, { x: 'Jun', y: 23.5 },
            { x: 'Jul', y: 26 }, { x: 'Aug', y: 25 },
            { x: 'Sep', y: 21 }, { x: 'Oct', y: 15 },
            { x: 'Nov', y: 15 }, { x: 'Dec', y: 15 }
        ];
        this.legendSettings = { visible: false };
        this.tilt = -45;
        this.radius = '100%';
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Various radius pie chart

You can assign different radii to each slice of the pie by fetching the radius from the data source and using it with the radius property in the series.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'




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

@Component({
imports: [
         CircularChart3DAllModule
    ],

providers: [CircularChart3DAllModule],
standalone: true,
    selector: 'app-container',
    template: `<ejs-circularchart3d style='display:block;' align='center' tilt='-15' [title]='title' [legendSettings]="legendSettings" [enableAnimation]='enableAnimation'>
    <e-circularchart3d-series-collection>
    <e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y' radius='r' innerRadius='20%' [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;
    public enableAnimation?: boolean;
    ngOnInit(): void {
        this.dataSource = [
          { x: 'Belgium', y: 551500, r: '110.7' },
          { x: 'Cuba', y: 312685, r: '124.6' },
          { x: 'Dominican Republic', y: 350000, r: '137.5' },
          { x: 'Egypt', y: 301000, r: '150.8' },
          { x: 'Kazakhstan', y: 300000, r: '155.5' },
          { x: 'Somalia', y: 357022, r: '160.6' },
          { x: 'Argentina', y: 505370, r: '100' },];
        this.title = 'Countries compared by population density and total area';
        this.legendSettings = { visible: true };
        this.enableAnimation= true
        this.dataLabel = {
            visible: true,
            name: 'x',
            position: 'Outside',
            font: {
                fontWeight: '600'
            },
            connectorStyle: { length: '40px' }
        };
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Donut chart

To achieve a donut in the pie series, customize the innerRadius property of the series. By setting a value greater than 0%, a donut will appear. The innerRadius property takes value from 0% to 100% of the pie radius.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'

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

@Component({
imports: [
         CircularChart3DAllModule
    ],

providers: [CircularChart3DAllModule],
standalone: true,
    selector: 'app-container',
    template: `<ejs-circularchart3d style='display:block;' align='center' [tilt]='tilt' [legendSettings]="legendSettings">
    <e-circularchart3d-series-collection>
    <e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y' [innerRadius]='innerRadius'>
    </e-circularchart3d-series></e-circularchart3d-series-collection>
    </ejs-circularchart3d>`
})

export class AppComponent implements OnInit {
    public dataSource?: Object[];
    public title?: string;
    public legendSettings?: Object;
    public innerRadius?: string;
    public tilt?: number;
    ngOnInit(): void {
        this.dataSource = [
            { x: 'Jan', y: 3 }, { x: 'Feb', y: 3.5 },
            { x: 'Mar', y: 7 }, { x: 'Apr', y: 13.5 },
            { x: 'May', y: 19 }, { x: 'Jun', y: 23.5 },
            { x: 'Jul', y: 26 }, { x: 'Aug', y: 25 },
            { x: 'Sep', y: 21 }, { x: 'Oct', y: 15 },
            { x: 'Nov', y: 15 }, { x: 'Dec', y: 15 }];
        this.innerRadius = '40%';
        this.legendSettings = { visible: false };
        this.tilt= -45
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Text and fill color mapping

The text and the fill color from the data source can be mapped to the 3D Circular Chart using pointColorMapping in the series and name in the data label, respectively.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'

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

@Component({
imports: [
         CircularChart3DAllModule
    ],

providers: [CircularChart3DAllModule],
standalone: true,
  selector: 'app-container',
  template: `<ejs-circularchart3d style='display:block;' align='center' [tilt]='tilt' [legendSettings]="legendSettings">
    <e-circularchart3d-series-collection>
    <e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y' [dataLabel]='dataLabel' [pointColorMapping]='pointColorMapping'>
    </e-circularchart3d-series></e-circularchart3d-series-collection>
    </ejs-circularchart3d>`
})
export class AppComponent implements OnInit {
  public dataSource?: Object[];
  public legendSettings?: Object;
  public dataLabel?: Object;
  public tilt?: number;
  public pointColorMapping?: string
  ngOnInit(): void {
    this.dataSource = [
      { x: 'Jan', y: 3, fill: '#498fff', text: 'January' },
      { x: 'Feb', y: 3.5, fill: '#ffa060', text: 'February' },
      { x: 'Mar', y: 7, fill: '#ff68b6', text: 'March' },
      { x: 'Apr', y: 13.5, fill: '#81e2a1', text: 'April' }
    ];
    this.dataLabel = {
      visible: true,
    };
    this.pointColorMapping = 'fill'
    this.legendSettings = { visible: false };
    this.tilt = -45
  }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Customization

Individual points in pie chart can be customized using the pointRender event.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'

import { Component, OnInit } from '@angular/core';
import { CircularChart3DPointRenderEventArgs } from '@syncfusion/ej2-charts';

@Component({
imports: [
         CircularChart3DAllModule
    ],

providers: [CircularChart3DAllModule],
standalone: true,
    selector: 'app-container',
    template: `<ejs-circularchart3d style='display:block;' align='center' (pointRender)="pointRender($event)" [tilt]='tilt' [legendSettings]="legendSettings">
    <e-circularchart3d-series-collection>
    <e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y'>
    </e-circularchart3d-series></e-circularchart3d-series-collection>
    </ejs-circularchart3d>`
})
export class AppComponent implements OnInit {
    public dataSource?: Object[];
    public legendSettings?: Object;
    public dataLabel?: Object;
    public tilt?: number;
    public pointRender: Function | any;;
    ngOnInit(): void {
        this.dataSource = [
          { x: 'Jan', y: 3 }, 
                { x: 'Feb', y: 3.5 },
                { x: 'Mar', y: 7 }, 
                { x: 'Apr', y: 13.5 }];
        this.legendSettings = { visible: false };
        this.pointRender = (args: CircularChart3DPointRenderEventArgs) => {
          if ((args.point.x as string).indexOf('Apr') > -1) {
              args.fill = '#f4bc42';
          }
          else if ((args.point.x as string).indexOf('Mar') > -1) {
              args.fill = '#DE3D8A';
          }
          else if ((args.point.x as string).indexOf('Feb') > -1) {
              args.fill = '#F7523F';
          }
          else {
              args.fill = '#597cf9';
          }
      }
        this.tilt= -45
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));