Legend in Angular 3D Circular Chart component
18 Nov 201824 minutes to read
The legend provides information about the data points rendered in the 3D Circular Chart. It can be added by enabling the visible option in the legendSettings property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart 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 legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
ngOnInit(): void {
this.dataSource = [
{ x: 'Jan', y: 13 },
{ x: 'Feb', y: 13 },
{ x: 'Mar', y: 17 },
{ x: 'Apr', y: 13.5 }
];
this.legendSettings = { visible: true };
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));To use the legends feature, inject the
CircularChartLegend3DServiceinto the@NgModule.providers.
Position and alignment
By using the position property, the legend can be positioned at the left, right, top or bottom of the 3D Circular Chart. By default, the legend will be positioned to the right of the 3D Circular Chart. Additionally, you can align the legend to the center, far or near of the chart using the alignment property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart 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 legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
ngOnInit(): void {
this.dataSource = [
{ x: 'Jan', y: 13 },
{ x: 'Feb', y: 13 },
{ x: 'Mar', y: 17 },
{ x: 'Apr', y: 13.5 }
];
this.legendSettings = { position: 'Top', alignment: 'Near' };
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend reverse
You can reverse the order of the legend items by using the reverse property in legendSettings. By default, the legend for the first series in the collection will be placed first.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart style='display:block;' align='center' [title]='title' subTitle='subTitle' [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 tilt?: number;
public title?: string;
public subTitle?: string;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
ngOnInit(): void {
this.dataSource = [
{ x: 'Saudi Arabia', y: 58 },
{ x: 'Persian Gulf', y: 15 },
{ x: 'Canada', y: 13 },
{ x: 'Venezuela', y: 8 },
{ x: 'Mexico', y: 3 },
{ x: 'Russia', y: 2 },
{ x: 'Miscellaneous', y: 1 }
];
this.legendSettings = {
visible: true,
reverse: true
};
this.title= 'Oil and other liquid imports in USA',
this.subTitle = 'In the year 2014 - 2015',
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend shape
To change the legend shape, use the legendShape property in the series. By default, the legend shape is set to seriesType.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart style='display:block;' align='center' [tilt]='tilt' [legendSettings]="legendSettings">
<e-circularchart3d-series-collection>
<e-circularchart3d-series [dataSource]='dataSource' xName='x' yName='y' legendShape='Rectangle'>
</e-circularchart3d-series></e-circularchart3d-series-collection>
</ejs-circularchart3d>`
})
export class AppComponent implements OnInit {
public dataSource?: Object[];
public legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
ngOnInit(): void {
this.dataSource = [
{ x: 'Jan', y: 13 },
{ x: 'Feb', y: 13 },
{ x: 'Mar', y: 17 },
{ x: 'Apr', y: 13.5 }
];
this.legendSettings = { visible: true };
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend size
The legend size can be changed by using the width and height properties in legendSettings.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart 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 legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
ngOnInit(): void {
this.dataSource = [
{ x: 'Jan', y: 13 },
{ x: 'Feb', y: 13 },
{ x: 'Mar', y: 17 },
{ x: 'Apr', y: 13.5 }
];
this.legendSettings = { width: '150', height: '100', border: { width: 1, color: 'pink'} };
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend item size
The size of the legend items can be customized by using the shapeHeight and shapeWidth properties in legendSettings.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart 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 legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
ngOnInit(): void {
this.dataSource = [
{ x: 'Jan', y: 13 },
{ x: 'Feb', y: 13 },
{ x: 'Mar', y: 17 },
{ x: 'Apr', y: 13.5 }
];
this.legendSettings = {
shapeHeight: 15,
shapeWidth: 15
};
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend paging
Paging will be enabled by default when the legend items exceed the legend bounds. Each legend item can be viewed by navigating between the pages using navigation buttons.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart 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 legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
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 = { height: '150', width: '80' };
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend text wrap
When the legend text exceeds the container, the text can be wrapped using the textWrap property in legendSettings. End users can also wrap the legend text based on the maximumLabelWidth property in legendSettings.
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': 'Net-tution', y: 21 },
{ 'x': 'Private Gifts', y: 8 },
{ 'x': 'All Other', y: 9 },
{ 'x': 'Local Revenue', y: 4 },
{ 'x': 'State Revenue', y: 21 },
{ 'x': 'Federal Revenue', y: 16 },
{ 'x': 'Self-supporting Operations', y: 21 }
];
this.innerRadius = '40%';
this.legendSettings = {
visible: true,
position: 'Right',
textWrap: 'Wrap',
maximumLabelWidth: 60
};
this.tilt = -45
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend title
You can set a title for the legend using the title property in legendSettings. The size, color, opacity, fontStyle, fontWeight, fontFamily, textAlignment, and textOverflow of the legend title can be customized using the titleStyle property in legendSettings.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart 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 legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
ngOnInit(): void {
this.dataSource = [
{ x: 'Jan', y: 13 },
{ x: 'Feb', y: 13 },
{ x: 'Mar', y: 17 },
{ x: 'Apr', y: 13.5 }
];
this.legendSettings = { visible: true, title: 'Months', position: 'Bottom' };
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Arrow page navigation
The page number will always be visible when using legend paging. However, it is now possible to disable the page number and enable page navigation with the left and right arrows. To render the arrow page navigation, set the enablePages property to false.
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 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 },
{ x: 'Nov', y: 15 }, { x: 'Dec', y: 15 }
];
this.legendSettings = {
width: '260px',
height: '50px',
enablePages: false,
position: 'Bottom'
};
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Legend item padding
The itemPadding property can be used to adjust the space between the legend items.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { CircularChart3DAllModule } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit, ViewChild } from '@angular/core';
import { CircularChart3DComponent } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
CircularChart3DAllModule
],
providers: [CircularChart3DAllModule],
standalone: true,
selector: 'app-container',
template: `
<ejs-circularchart3d #chart 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 legendSettings?: Object;
public tilt?: number;
@ViewChild('chart')
public chartObj?: CircularChart3DComponent;
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 = {
width: '260px',
height: '50px',
position: 'Bottom',
itemPadding: 30
};
this.tilt = -45;
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));