Selection in Angular 3D Chart control
27 Apr 202424 minutes to read
The 3D chart provides selection support for the series and its data points on mouse click.
When mouse is clicked on the data points, the corresponding series legend will also be selected.
We have different types of selection mode for selecting a data.
- None
- Point
- Series
- Cluster
Point
To select a point, set the selectionMode
property to Point.
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 style='display:block;' align='center' [primaryXAxis]='primaryXAxis' [selectionMode]="selection"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze'>
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public selection?: String;
public enableRotation?: boolean;
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',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
};
this.enableRotation = true;
this.selection = "Point";
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Series
To select a series, set the selectionMode
property to 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 style='display:block;' align='center' [primaryXAxis]='primaryXAxis' [selectionMode]="selection"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze'>
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public selection?: String;
public enableRotation?: boolean;
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',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
};
this.enableRotation = true;
this.selection = "Series";
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Cluster
To select the points that corresponds to the same index in all the series, set the selectionMode
property to Cluster.
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 style='display:block;' align='center' [primaryXAxis]='primaryXAxis' [selectionMode]="selection"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze'>
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public selection?: String;
public enableRotation?: boolean;
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',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
};
this.enableRotation = true;
this.selection = "Cluster";
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Selection type
To select multiple points or series, enable the isMultiSelect
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 style='display:block;' align='center' [primaryXAxis]='primaryXAxis' [selectionMode]="selection" [isMultiSelect]=true
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze'>
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public primaryXAxis?: Object;
public selection?: String;
public enableRotation?: boolean;
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',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
};
this.enableRotation = true;
this.selection = "Point";
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Selection during initial loading
In a 3D chart, selecting a point or series during initial loading can only be done programmatically. The selectedDataIndexes
property can be used for this.
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 style='display:block;' align='center' [primaryXAxis]='primaryXAxis' [selectionMode]="selection" [isMultiSelect]=true [selectedDataIndexes]="selectedDataIndexes"
rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
<e-chart3d-series-collection>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='gold'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='silver'>
</e-chart3d-series>
<e-chart3d-series [dataSource]='dataSource' type='Column' xName='country' yName='bronze'>
</e-chart3d-series>
</e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
public dataSource?: Object[];
public selectedDataIndexes?: Object[];
public primaryXAxis?: Object;
public selection?: String;
public enableRotation?: boolean;
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',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
};
this.enableRotation = true;
this.selection = "Point";
this.selectedDataIndexes = [
{ series: 0, point: 1}, { series: 2, point: 3}
];
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Selection through legend
To select a point or series through legend use the toggleVisibility
property. Also, use enableHighlight
property for highlighting the series through legend.
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 style='display:block;' align='center' [primaryXAxis]='primaryXAxis' [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 legend?: Object;
public enableRotation?: boolean;
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',
labelRotation: -45,
labelPlacement: 'BetweenTicks'
};
this.enableRotation = true;
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));