100% Stacked Bar in Angular Chart component
19 Sep 202424 minutes to read
100% Stacked bar
To render a 100% stacked bar series in your chart, you need to follow a few steps to configure it correctly. Here’s a concise guide on how to do this:
-
Set the series type: Define the series
type
asStackingBar100
in your chart configuration. This indicates that the data should be represented as a 100% stacked bar chart, with segments that show the percentage contribution of each part. -
Inject the StackingBarSeries module: Use the
@NgModule.providers
method to inject theStackingBarSeriesService
module into your chart. This step is essential, as it ensures that the necessary functionalities for rendering the 100% stacked bar series are available in your chart.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Binding data with series
You can bind data to the chart using the dataSource
property within the series configuration. This allows you to connect a JSON dataset or remote data to your chart. To display the data correctly, map the fields from the data to the chart series xName
and yName
properties.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Series customization
The following properties can be used to customize the 100% stacked bar
series.
Fill
The fill property determines the color applied to the series.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' fill='yellow'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' fill='green'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' fill='blue'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
The fill property can be used to apply a gradient color to the 100% stacked bar series. By configuring this property with gradient values, you can create a visually appealing effect in which the color transitions smoothly from one shade to another.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' fill='url(#gradient)'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' fill='url(#gradient1)'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' fill='url(#gradient2)'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Opacity
The opacity property specifies the transparency level of the fill. Adjusting this property allows you to control how opaque or transparent the fill color of the series appears.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' opacity='0.5'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' opacity='0.5'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' opacity='0.5'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Dash array
The dashArray property determines the pattern of dashes and gaps in the series.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' [border]='border' [dashArray]='2'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' [border]='border' [dashArray]='2'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' [border]='border' [dashArray]='2'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
public border?: Object;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
this.border = { width: 1.5, color: 'red' };
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Border
Use the border property to customize the width and color of the series border.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' [border]='border'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' [border]='border'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' [border]='border'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
public border?: Object;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
this.border = { width: 1.5, color: 'red' };
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
100% Cylindrical stacked bar chart
To render a 100% cylindrical stacked bar chart, set the columnFacet
property to Cylinder
in the chart series. This property transforms the regular 100% stacked bars into cylindrical shapes, enhancing the visual representation of the data.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { cylindricalData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' columnFacet= 'Cylinder' xName='x' yName='y'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' columnFacet= 'Cylinder' xName='x' yName='y1'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' columnFacet= 'Cylinder' xName='x' yName='y2'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public chartData?: Object[];
primaryXAxis: any;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = cylindricalData;
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let cylindricalData: Object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Empty points
Data points with null
or undefined
values are considered empty. Empty data points are ignored and not plotted on the chart.
Mode
Use the mode
property to define how empty or missing data points are handled in the series. The default mode for empty points is Gap
.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' [emptyPointSettings]='emptyPointSettings></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' [emptyPointSettings]='emptyPointSettings1'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' [emptyPointSettings]='emptyPointSettings2'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public emptyPointSettings?: object;
public emptyPointSettings1?: object;
public emptyPointSettings2?: object;
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
this.emptyPointSettings = {mode: 'Zero'}
this.emptyPointSettings1 = {mode: 'Gap'}
this.emptyPointSettings2 = {mode: 'Average'}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Fill
Use the fill
property to customize the fill color of empty points in the series.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' [emptyPointSettings]='emptyPointSettings></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' [emptyPointSettings]='emptyPointSettings1'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' [emptyPointSettings]='emptyPointSettings2'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public emptyPointSettings?: object;
public emptyPointSettings1?: object;
public emptyPointSettings2?: object;
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
this.emptyPointSettings = {mode: 'Zero'}
this.emptyPointSettings1 = {mode: 'Gap'}
this.emptyPointSettings2 = {mode: 'Average', fill: 'red'}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Border
Use the border
property to customize the width and color of the border for empty points.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' [emptyPointSettings]='emptyPointSettings'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange' [emptyPointSettings]='emptyPointSettings1'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage' [emptyPointSettings]='emptyPointSettings2'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public emptyPointSettings?: object;
public emptyPointSettings1?: object;
public emptyPointSettings2?: object;
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
this.emptyPointSettings = {mode: 'Zero'}
this.emptyPointSettings1 = {mode: 'Gap'}
this.emptyPointSettings2 = {mode: 'Average', fill: 'red', border: {width: 1.5, color:'green'}}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Events
Series render
The seriesRender
event allows you to customize series properties, such as data, fill, and name, before they are rendered on the chart.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { ISeriesRenderEventArgs } from '@syncfusion/ej2-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" (seriesRender)='seriesRender($event)' [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' ></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
}
public seriesRender(args: ISeriesRenderEventArgs) {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];
Point render
The pointRender
event allows you to customize each data point before it is rendered on the chart.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { IPointRenderEventArgs } from '@syncfusion/ej2-charts'
import { BarSeriesService, StackingBarSeriesService, CategoryService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { stackedData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ BarSeriesService, StackingBarSeriesService, CategoryService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" (pointRender)='pointRender($event)' [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y' name='Apple' ></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y1' name='Orange'></e-series>
<e-series [dataSource]='chartData' type='StackingBar100' xName='x' yName='y2' name='Wastage'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = stackedData;
this.primaryXAxis = {
valueType: 'Category',
title: 'Months'
};
this.title = 'Sales Comparison';
}
public pointRender(args: IPointRenderEventArgs) {
if (args.point.index % 2 !==0 ) {
args.fill = '#ff6347';
}
else {
args.fill = '#009cb8';
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];