Stacked bar chart in Angular 3D Chart control

27 Apr 202413 minutes to read

Stacked bar chart

To render a stacked bar series, use series type as StackingBar and inject StackingBarSeries3DService module into the @NgModule.providers.

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'
    rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
    <e-chart3d-series-collection>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y' name="America">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y1' name="Canada">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y2' name="France">
        </e-chart3d-series>
    </e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
    public dataSource?: Object[];
    public primaryXAxis?: Object;
    public enableRotation?: boolean;
    ngOnInit(): void {
        this.dataSource = [
            { x: 'Sochi', y: 9, y1: 10, y2: 4 },
            { x: 'Rio', y: 46, y1: 4, y2: 10 },
            { x: 'Pyeongchang', y: 9, y1: 11, y2: 5 },
            { x: 'Tokyo', y: 39, y1: 7, y2: 10 },
            { x: 'Beijing', y: 8, y1: 4, y2: 5 }
        ];
        this.primaryXAxis = {
            valueType: 'Category',
            labelRotation: -45,
            labelPlacement: 'BetweenTicks'
        };
        this.enableRotation = true;
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Stacking group

To group the stacked bar, the stackingGroup property can be used. The columns with same group name are stacked on top of each other.

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'
    rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
    <e-chart3d-series-collection>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y' name="America" stackingGroup="JohnAndAndrew">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y1' name="Canada" stackingGroup="JohnAndAndrew">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y2' name="France" stackingGroup="ThomasAndMichael">
        </e-chart3d-series>
    </e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
    public dataSource?: Object[];
    public primaryXAxis?: Object;
    public enableRotation?: boolean;
    ngOnInit(): void {
        this.dataSource = [
            { x: 'Sochi', y: 9, y1: 10, y2: 4 },
            { x: 'Rio', y: 46, y1: 4, y2: 10 },
            { x: 'Pyeongchang', y: 9, y1: 11, y2: 5 },
            { x: 'Tokyo', y: 39, y1: 7, y2: 10 },
            { x: 'Beijing', y: 8, y1: 4, y2: 5 }
        ];
        this.primaryXAxis = {
            valueType: 'Category',
            labelRotation: -45,
            labelPlacement: 'BetweenTicks'
        };
        this.enableRotation = true;
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Cylindrical stacked bar chart

To render a cylindrical stacked bar chart, set the columnFacet property to Cylinder in the chart 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'
    rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
    <e-chart3d-series-collection>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y' name="America" columnFacet="Cylinder">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y1' name="Canada" columnFacet="Cylinder">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y2' name="France" columnFacet="Cylinder">
        </e-chart3d-series>
    </e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
    public dataSource?: Object[];
    public primaryXAxis?: Object;
    public enableRotation?: boolean;
    ngOnInit(): void {
        this.dataSource = [
            { x: 'Sochi', y: 9, y1: 10, y2: 4 },
            { x: 'Rio', y: 46, y1: 4, y2: 10 },
            { x: 'Pyeongchang', y: 9, y1: 11, y2: 5 },
            { x: 'Tokyo', y: 39, y1: 7, y2: 10 },
            { x: 'Beijing', y: 8, y1: 4, y2: 5 }
        ];
        this.primaryXAxis = {
            valueType: 'Category',
            labelRotation: -45,
            labelPlacement: 'BetweenTicks'
        };
        this.enableRotation = true;
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));

Series customization

The following properties can be used to customize the stacked bar series.

  • fill – Specifies the color of the series.
  • opacity – Specifies the opacity of the fill color.
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'
    rotation=7 tilt=10 depth=100 [enableRotation]='enableRotation'>
    <e-chart3d-series-collection>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y' name="America" fill="red">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y1' name="Canada" fill="green">
        </e-chart3d-series>
        <e-chart3d-series [dataSource]='dataSource' type='StackingBar' xName='x' yName='y2' name="France" fill="yellow">
        </e-chart3d-series>
    </e-chart3d-series-collection>
</ejs-chart3d>`
})
export class AppComponent {
    public dataSource?: Object[];
    public primaryXAxis?: Object;
    public enableRotation?: boolean;
    ngOnInit(): void {
        this.dataSource = [
            { x: 'Sochi', y: 9, y1: 10, y2: 4 },
            { x: 'Rio', y: 46, y1: 4, y2: 10 },
            { x: 'Pyeongchang', y: 9, y1: 11, y2: 5 },
            { x: 'Tokyo', y: 39, y1: 7, y2: 10 },
            { x: 'Beijing', y: 8, y1: 4, y2: 5 }
        ];
        this.primaryXAxis = {
            valueType: 'Category',
            labelRotation: -45,
            labelPlacement: 'BetweenTicks'
        };
        this.enableRotation = true;
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));