Legend in Angular 3D Chart control
27 Apr 202424 minutes to read
Legend provides information about the series rendered in the 3D chart.
Position and alignment
By using the position
property, the legend can be positioned at left, right, top or bottom of the 3D chart. The legend is positioned at the bottom of the 3D chart, by default.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
//Legend position as top
position:'Top'
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
The custom position helps you to position the legend anywhere in the 3D chart using x and y coordinates.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
position:'Custom',
location: { x: 200, y: 20 }
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Legend reverse
The order of the legend items can be reversed by using the reverse
property. By default, legend for the first series in the collection will be placed first.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
reverse: true
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Legend alignment
The legend can be aligned at near, far or center to the 3D chart using the alignment
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
position:'Top',
alignment: 'Near'
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Legend customization
To change the legend icon shape, legendShape
property in the series
can be used. By default, the legend icon shape is seriesType
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold" legendShape="Circle">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" legendShape="SeriesType">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze" legendShape="Rectangle">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Legend size
By default, legend takes 20% - 25% of the 3D chart’s height horizontally, when it is placed on top or bottom position and 20% - 25% of the 3D chart’s width vertically, when it is placed on left or right position. You can change this default legend size by using the height
and width
properties of the legendSettings
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold" legendShape="Circle">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" legendShape="Circle">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze" legendShape="Circle">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
width: '500', height: '100',
border: { width: 1, color: 'pink'}
};
}
}
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 customised by using the shapeHeight
and shapeWidth
properties.\
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold" legendShape="Circle">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" legendShape="Circle">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze" legendShape="Circle">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
shapeHeight: 10, shapeWidth: 10
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Paging for legend
Paging will be enabled by default, when the legend items exceeds the legend bounds. Each legend items can be viewed by navigating between the pages using navigation buttons.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='x' yName='y' name="December 2007">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='x' yName='y1' name="December 2008" >
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='x' yName='y2' name="December 2009">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='x' yName='y3' name="December 2010">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ x: 'WW', y: 12, y1: 22, y2: 38.3, y3: 50 },
{ x: 'EU', y: 9.9, y1: 26, y2: 45.2, y3: 63.6 },
{ x: 'APAC', y: 4.4, y1: 9.3, y2: 18.2, y3: 20.9 },
{ x: 'LATAM', y: 6.4, y1: 28, y2: 46.7, y3: 65.1 },
{ x: 'MEA', y: 30, y1: 45.7, y2: 61.5, y3: 73 },
{ x: 'NA', y: 25.3, y1: 35.9, y2: 64, y3: 81.4 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
padding: 10, shapePadding: 10,
visible: true, border: {
width: 2, color: 'grey'
},
width: '200'
};
}
}
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 by using the textWrap
property. End user can also wrap the legend text based on the maximumLabelWidth
property.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" >
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
position:'Right',
textWrap:'Wrap',
maximumLabelWidth:50,
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Series selection through legend
By default, you can collapse the series visibility by clicking the legend. On the other hand, turn off the toggleVisibility
property if you must use a legend click to choose a series.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" >
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
toggleVisibility: false,
enableHighlight: true
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Collapsing legend item
By default, series name will be displayed as legend. To skip the legend for a particular series, you can give empty string to the series name.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" >
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
title: 'Countries'
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
toggleVisibility: true
};
}
}
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 title for legend using title
property in legendSettings
. The size
, color
, opacity
,fontStyle
, fontWeight
, fontFamily
, textAlignment
, and textOverflow
of legend title can be customized by using the titleStyle
property in legendSettings
. The titlePosition
is used to set the legend position in Top
, Left
and Right
position. The maximumTitleWidth
is used to set the width of the legend title. By default, it will be 100px
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" >
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
title: 'Countries'
};
}
}
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 while using legend paging. It is now possible to disable the page number and enable page navigation with the left and right arrows. The enablePages
property needs to be set to false in order to render the arrow page navigation.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" >
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
visible: true,
width: '180',
height: '20',
enablePages: false
};
}
}
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 { Chart3DAllModule} from '@syncfusion/ej2-angular-charts'
import { Component } from '@angular/core';
@Component({
imports: [
Chart3DAllModule
],
standalone: true,
selector: 'app-container',
// specifies the template string for the Chart component
template: `<ejs-chart3d [primaryXAxis]='primaryXAxis' [primaryYAxis]="primaryYAxis" [legendSettings]="legend"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold' name="Gold">
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver' name="Silver" >
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze' name="Bronze">
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public enableRotation?: boolean;
public legend?: Object;
public primaryYAxis?: Object;
ngOnInit(): void {
this.dataSource = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
this.primaryXAxis = {
valueType: 'Category',
};
this.enableRotation = true;
this.primaryYAxis = {
minimum: 0, maximum: 80,
interval: 20, title: 'Medals'
};
this.legend = {
enablePages: false,
itemPadding: 30
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Note: To use the legend feature, we need to inject the
Legend3DService
module into the@NgModule.providers
.