Data Labels in Angular Charts
Data labels display the values of data points directly on the chart, reducing the need to reference axes for exact values. Labels automatically adjust to avoid overlapping and maintain readability.

Data labels can be added to a chart series by setting the visible option to true in the dataLabel property of the series marker. By default, the labels arrange smartly without overlapping.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
valueType: 'Category'
};
this.marker = { dataLabel: { visible: true }
};
this.title = 'Alaska Weather Statistics - 2016';
}
}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 DataLabel feature, inject
DataLabelServiceinto the@NgModule.providers.
Position
Use the position property to place data labels at Top, Middle, Bottom, or Outer (applicable only to column and bar series). Appropriate label positioning enhances clarity and preserves chart readability.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
valueType: 'Category'
};
this.marker = { dataLabel: { visible: true, position: 'Middle' }
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Note: The
Outerposition applies only to column and bar series types.
Data Label Template
Customize label content using templates. Use placeholders such as ${point.x} and ${point.y} to display data point values. The template property enables fully customizable and visually rich labels.
Define a template via a script element
Add a script element with a unique id in the page’s index.html. In this example, the color field from the data source is mapped to the template’s background:
<script id="index" type="text/x-template">
<div id='templateWrap' style="background-color: ${point.color}; border-radius: 3px;"><span>${point.y}</span></div>
</script>Then reference that id from the template property in the dataLabel configuration:
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { LineSeriesService, DateTimeService, DataLabelService, StackingColumnSeriesService, CategoryService,
StepAreaSeriesService,ChartAnnotationService, LegendService, TooltipService} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
@Component({
imports: [
ChartModule
],
providers: [ LineSeriesService, DateTimeService, DataLabelService, StackingColumnSeriesService,CategoryService,
StepAreaSeriesService,ChartAnnotationService, LegendService, TooltipService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='Line' xName='x' yName='y' name='Female' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public chartData?: Object[];
public title?: string;
public marker?: Object;
ngOnInit(): void {
this.chartData =[
{ x: 10, y: 7000, color: 'red' },
{ x: 20, y: 1000, color: 'yellow' },
{ x: 30, y: 12000, color: 'orange' },
{ x: 40, y: 14000, color: 'skyblue' },
{ x: 50, y: 11000, color: 'blue' },
{ x: 60, y: 5000, color: 'green' },
{ x: 70, y: 7300, color: 'pink' },
{ x: 80, y: 9000, color: 'white' },
{ x: 90, y: 12000, color: 'magenta' },
{ x: 100, y: 14000, color: 'purple' },
{ x: 110, y: 11000, color: 'teal' },
{ x: 120, y: 5000, color: 'gray' },
];
this.marker = { visible: true, dataLabel: { visible: true, name: 'color', template: '#index' }};
this.title = 'Sales Rate in USA';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Define a template inline
You can also define the template HTML inline as a string in app.component.ts, using the same placeholders:
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public marker?: Object;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
title: 'Months',
valueType: 'Category', labelFormat: 'yMMM',
edgeLabelPlacement: 'Shift'
};
this.marker = { dataLabel: { visible: true, position: 'Middle',
template: '<div>${point.x}</div><div>${point.y}</div>' }
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Format
Apply number or date formatting using the format property. Global formatting symbols include:
-
n– number format -
p– percentage format -
c– currency format
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public marker?: Object;
primaryYAxis: any;
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
title: 'Months',
valueType: 'Category', labelFormat: 'yMMM',
edgeLabelPlacement: 'Shift'
};
this.marker = { dataLabel: { visible: true, format: 'p1'}
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));| Value | Format | Resultant Value | Description |
|---|---|---|---|
| 1000 | n1 | 1000.0 | The number is rounded to 1 decimal place. |
| 1000 | n2 | 1000.00 | The number is rounded to 2 decimal places. |
| 1000 | n3 | 1000.000 | The number is rounded to 3 decimal places. |
| 0.01 | p1 | 1.0% | The number is converted to percentage with 1 decimal place. |
| 0.01 | p2 | 1.00% | The number is converted to percentage with 2 decimal places. |
| 0.01 | p3 | 1.000% | The number is converted to percentage with 3 decimal places. |
| 1000 | c1 | $1000.0 | The currency symbol is appended to the number and the number is rounded to 1 decimal place. |
| 1000 | c2 | $1000.00 | The currency symbol is appended to the number and the number is rounded to 2 decimal places. |
Text Mapping
Display custom text using the name property, which maps label text from a specific field in the data source. This feature is useful for descriptive or category‑based labels.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { mapData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = mapData;
this.primaryXAxis = {
valueType: 'Category'
};
this.marker = { dataLabel: { visible: true, name: 'text'}
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Margin
Adjust spacing around labels using the margin property, which includes left, right, bottom, and top values. Margins help prevent labels from overlapping chart elements.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
valueType: 'Category'
};
this.marker = { dataLabel: { visible: true,border:{width: 1, color : 'red'},
margin:{
left:5,
right:5,
top:5,
bottom:5
} }
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Data Label Rotation
Rotate data labels using the angle property. Rotation improves readability when labels are long or when space is limited.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
valueType: 'Category'
};
this.marker = { dataLabel: { visible: true, border:{width: 1, color : 'red'},
margin:{
left:5,
right:5,
top:5,
bottom:5
}, angle : 45, enableRotation: true }
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Customization
Enhance label appearance using properties such as fill (background), border, and corner radius (rx, ry). Refine text appearance using the font settings, which support color, fontFamily, fontWeight, and size.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, 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='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
valueType: 'Category'
};
this.marker = { dataLabel: { visible: true,
border:{width: 2, color : 'red'},
rx:10, ry: 10
}
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Note: The
rxandryproperties require non‑nullbordervalues.
Handling Overlapping Data Labels
Use the labelIntersectAction property to specify how overlapping data labels are handled.
The available options are:
-
None- Displays all data labels even when they overlap. -
Hide- Hides overlapping data labels. -
Rotate90- Rotates overlapping data labels by 90 degrees. -
RelocateVertically- Relocates overlapping data labels vertically. -
RelocateHorizontally- Relocates overlapping data labels horizontally.
The RelocateVertically and RelocateHorizontally options are supported only for the following series types:
StackingColumnStackingColumn100StackingBarStackingBar100
These relocation modes improve readability by relocating overlapping data labels and connecting them to their corresponding data points using connector lines. Use the smartLabelSettings property to customize relocated labels through the background, pointerShape, border, connectorLineStyle, and offset settings. The offset property is applicable only when labelIntersectAction is set to RelocateVertically. Note that the seriesOverlapAction property in smartLabelSettings is not applicable for RelocateVertically and RelocateHorizontally.
import { Component, ViewEncapsulation } from '@angular/core';
import { ChartModule, StackingColumnSeriesService, CategoryService, LegendService, DataLabelService, TooltipService } from '@syncfusion/ej2-angular-charts';
import { dataA, dataB, dataC, dataD, dataE, dataF, dataG, dataH } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ StackingColumnSeriesService, CategoryService, LegendService, DataLabelService, TooltipService ],
standalone: true,
selector: 'app-container',
template: `
<div class="control-section">
<div align="center">
<ejs-chart id="chartcontainer" style="display:block;" [title]="title" [tooltip]="tooltip" [legendSettings]="legendSettings" [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis">
<e-series-collection>
<e-series [dataSource]="dataA" type="StackingColumn" xName="x" yName="y" name="Category A" fill="#254061" [columnWidth]="0.6" [marker]="marker"></e-series>
<e-series [dataSource]="dataB" type="StackingColumn" xName="x" yName="y" name="Category B" fill="#376092" [columnWidth]="0.6" [marker]="marker"></e-series>
<e-series [dataSource]="dataC" type="StackingColumn" xName="x" yName="y" name="Category C" fill="#4f81bd" [columnWidth]="0.6" [marker]="marker"></e-series>
<e-series [dataSource]="dataD" type="StackingColumn" xName="x" yName="y" name="Category D" fill="CornflowerBlue" [columnWidth]="0.6" [marker]="marker"></e-series>
<e-series [dataSource]="dataE" type="StackingColumn" xName="x" yName="y" name="Category E" fill="LightBlue" [columnWidth]="0.6" [marker]="marker"></e-series>
<e-series [dataSource]="dataF" type="StackingColumn" xName="x" yName="y" name="Category F" fill="LightSteelBlue" [columnWidth]="0.6" [marker]="marker"></e-series>
<e-series [dataSource]="dataG" type="StackingColumn" xName="x" yName="y" name="Category G" fill="Moccasin" [columnWidth]="0.6" [marker]="marker"></e-series>
<e-series [dataSource]="dataH" type="StackingColumn" xName="x" yName="y" name="Category H" fill="LightGrey" [columnWidth]="0.6" [marker]="marker"></e-series>
</e-series-collection>
</ejs-chart>
</div>
</div>
`,
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public dataA: Object[] = dataA;
public dataB: Object[] = dataB;
public dataC: Object[] = dataC;
public dataD: Object[] = dataD;
public dataE: Object[] = dataE;
public dataF: Object[] = dataF;
public dataG: Object[] = dataG;
public dataH: Object[] = dataH;
public primaryXAxis: Object = {
valueType: 'Category'
};
public primaryYAxis: Object = {
visible: false
};
public title: string = 'Chart Title';
public tooltip: Object = {
enable: true
};
public legendSettings: Object = {
visible: true
};
public marker: Object = {
dataLabel: {
visible: true,
name: 'text',
fill: 'Transparent',
labelIntersectAction: 'RelocateVertically',
smartLabelSettings: {
background: '#4f4f4f',
border: {
color: 'black',
dashArray: '2',
width: 2
},
connectorLineStyle: {
color: 'black',
width: 2
},
pointerShape: 'Arrow',
offset: 0.5
}
}
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
bootstrapApplication(AppComponent).catch((err) => console.error(err));export const dataA: Object[] = [
{ x: 'Period 1', y: 35, text: '35%' },
{ x: 'Period 2', y: 30, text: '30%' },
{ x: 'Period 3', y: 32, text: '32%' }
];
export const dataB: Object[] = [
{ x: 'Period 1', y: 22, text: '22%' },
{ x: 'Period 2', y: 25, text: '25%' },
{ x: 'Period 3', y: 24, text: '24%' }
];
export const dataC: Object[] = [
{ x: 'Period 1', y: 14, text: '14%' },
{ x: 'Period 2', y: 16, text: '16%' },
{ x: 'Period 3', y: 15, text: '15%' }
];
export const dataD: Object[] = [
{ x: 'Period 1', y: 10, text: '10%' },
{ x: 'Period 2', y: 11, text: '11%' },
{ x: 'Period 3', y: 12, text: '12%' }
];
export const dataE: Object[] = [
{ x: 'Period 1', y: 7, text: '7%' },
{ x: 'Period 2', y: 8, text: '8%' },
{ x: 'Period 3', y: 6, text: '6%' }
];
export const dataF: Object[] = [
{ x: 'Period 1', y: 5, text: '5%' },
{ x: 'Period 2', y: 5, text: '5%' },
{ x: 'Period 3', y: 5, text: '5%' }
];
export const dataG: Object[] = [
{ x: 'Period 1', y: 4, text: '4%' },
{ x: 'Period 2', y: 3, text: '3%' },
{ x: 'Period 3', y: 4, text: '4%' }
];
export const dataH: Object[] = [
{ x: 'Period 1', y: 3, text: '3%' },
{ x: 'Period 2', y: 2, text: '2%' },
{ x: 'Period 3', y: 2, text: '2%' }
];Smart Label
Smart Label places data labels of Cartesian series so that they do not overlap each other, the markers, or the plot area boundary. Enable it by setting the enableSmartLabels property to true. The default value is false.
How it works:
- Positioning: A label stays at its default position when that position is free. Otherwise, the label is checked around its point at the top, right, bottom, and left positions, and then at the diagonal positions. The first position that is inside the plot area of its series and does not overlap any other label or marker is used. For example, if the top and right positions collide with other labels, the label is placed at the bottom when there is enough space. If no free position is found, the label is hidden.
- Label and marker detection: A label is checked against the other data labels and the visible markers of all series.
- Connector line: A relocated label that is more than 12 px away from its point is joined to the point with a connector line and an arrow pointer.
import { ChartModule } from '@syncfusion/ej2-angular-charts';
import { LineSeriesService, LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
@Component({
imports: [
ChartModule
],
providers: [LineSeriesService, LegendService, DataLabelService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis' [enableSmartLabels]='true' [title]='title' [subTitle]='subTitle'>
<e-series-collection>
<e-series [dataSource]='vietnam' type='Line' xName='x' yName='y' name='Vietnam' width=2 [animation]='animation' [marker]='vietnamMarker'></e-series>
<e-series [dataSource]='indonesia' type='Line' xName='x' yName='y' name='Indonesia' width=2 [animation]='animation' [marker]='indonesiaMarker'></e-series>
<e-series [dataSource]='france' type='Line' xName='x' yName='y' name='France' width=2 [animation]='animation' [marker]='franceMarker'></e-series>
<e-series [dataSource]='poland' type='Line' xName='x' yName='y' name='Poland' width=2 [animation]='animation' [marker]='polandMarker'></e-series>
<e-series [dataSource]='mexico' type='Line' xName='x' yName='y' name='Mexico' width=2 [animation]='animation' [marker]='mexicoMarker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public title?: string;
public subTitle?: string;
public animation?: Object;
public vietnam?: Object[];
public indonesia?: Object[];
public france?: Object[];
public poland?: Object[];
public mexico?: Object[];
public vietnamMarker?: Object;
public indonesiaMarker?: Object;
public franceMarker?: Object;
public polandMarker?: Object;
public mexicoMarker?: Object;
ngOnInit(): void {
this.vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
this.indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
this.france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
this.poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
this.mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];
this.primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
this.primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
this.animation = { enable: false };
this.vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: { visible: true }
};
this.indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
this.franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
this.polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
this.mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
this.title = 'Annual Crude Steel Production by Country (2016–2024)';
this.subTitle = 'Source: wikipedia.org';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Note: When Smart Label is enabled,
labelIntersectActionis ignored, and the data labelpositiondecides only the default position. Stacked column and bar series continue to use theRelocateVerticallyandRelocateHorizontallyoptions.
Duplicate data labels
Use the showDuplicateLabels property of the chart to control labels that have the same text at the same location, such as labels of multiple series with identical values.
-
true(default) - Renders all the labels. -
false- Renders only the first label and skips the others. The first label is decided by the series order and then the point order.
This property works with or without enableSmartLabels.
import { ChartModule } from '@syncfusion/ej2-angular-charts';
import { LineSeriesService, LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
@Component({
imports: [
ChartModule
],
providers: [LineSeriesService, LegendService, DataLabelService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis' [enableSmartLabels]='true' [showDuplicateLabels]='false' [title]='title' [subTitle]='subTitle'>
<e-series-collection>
<e-series [dataSource]='vietnam' type='Line' xName='x' yName='y' name='Vietnam' width=2 [animation]='animation' [marker]='vietnamMarker'></e-series>
<e-series [dataSource]='indonesia' type='Line' xName='x' yName='y' name='Indonesia' width=2 [animation]='animation' [marker]='indonesiaMarker'></e-series>
<e-series [dataSource]='france' type='Line' xName='x' yName='y' name='France' width=2 [animation]='animation' [marker]='franceMarker'></e-series>
<e-series [dataSource]='poland' type='Line' xName='x' yName='y' name='Poland' width=2 [animation]='animation' [marker]='polandMarker'></e-series>
<e-series [dataSource]='mexico' type='Line' xName='x' yName='y' name='Mexico' width=2 [animation]='animation' [marker]='mexicoMarker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public title?: string;
public subTitle?: string;
public animation?: Object;
public vietnam?: Object[];
public indonesia?: Object[];
public france?: Object[];
public poland?: Object[];
public mexico?: Object[];
public vietnamMarker?: Object;
public indonesiaMarker?: Object;
public franceMarker?: Object;
public polandMarker?: Object;
public mexicoMarker?: Object;
ngOnInit(): void {
this.vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
this.indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
this.france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
this.poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
this.mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];
this.primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
this.primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
this.animation = { enable: false };
this.vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: { visible: true }
};
this.indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
this.franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
this.polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
this.mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
this.title = 'Annual Crude Steel Production by Country (2016–2024)';
this.subTitle = 'Source: wikipedia.org';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Customization
Use the smartLabelSettings property in the series dataLabel to customize relocated labels and their connector lines. Labels at their default position keep the dataLabel settings.
-
background- Sets the background color of the relocated label. -
border- Sets thecolor,width, anddashArrayof the relocated label border. -
pointerShape- Sets the pointer at the point end of the connector line. The options areArrow(default) andNone. -
connectorLineStyle- Sets thecolor,width, andopacityof the connector line and pointer. Setwidthto0orcolortotransparentto hide the line. -
seriesOverlapAction- Specifies whether labels avoid series elements. See Series overlap action.
Note: The
offsetproperty is not applicable when Smart Label is enabled, because Smart Label automatically determines the final label position to avoid overlaps.
import { ChartModule } from '@syncfusion/ej2-angular-charts';
import { LineSeriesService, LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
@Component({
imports: [
ChartModule
],
providers: [LineSeriesService, LegendService, DataLabelService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis' [enableSmartLabels]='true' [title]='title' [subTitle]='subTitle'>
<e-series-collection>
<e-series [dataSource]='vietnam' type='Line' xName='x' yName='y' name='Vietnam' width=2 [animation]='animation' [marker]='vietnamMarker'></e-series>
<e-series [dataSource]='indonesia' type='Line' xName='x' yName='y' name='Indonesia' width=2 [animation]='animation' [marker]='indonesiaMarker'></e-series>
<e-series [dataSource]='france' type='Line' xName='x' yName='y' name='France' width=2 [animation]='animation' [marker]='franceMarker'></e-series>
<e-series [dataSource]='poland' type='Line' xName='x' yName='y' name='Poland' width=2 [animation]='animation' [marker]='polandMarker'></e-series>
<e-series [dataSource]='mexico' type='Line' xName='x' yName='y' name='Mexico' width=2 [animation]='animation' [marker]='mexicoMarker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public title?: string;
public subTitle?: string;
public animation?: Object;
public vietnam?: Object[];
public indonesia?: Object[];
public france?: Object[];
public poland?: Object[];
public mexico?: Object[];
public vietnamMarker?: Object;
public indonesiaMarker?: Object;
public franceMarker?: Object;
public polandMarker?: Object;
public mexicoMarker?: Object;
ngOnInit(): void {
this.vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
this.indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
this.france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
this.poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
this.mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];
this.primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
this.primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
this.animation = { enable: false };
this.vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
background: '#e0e0e0',
border: { color: '#404040', width: 1 },
pointerShape: 'Arrow',
connectorLineStyle: { color: '#404040', width: 1.5 }
}
}
};
this.indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: { visible: true }
};
this.franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: { visible: true }
};
this.polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: { visible: true }
};
this.mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: { visible: true }
};
this.title = 'Annual Crude Steel Production by Country (2016–2024)';
this.subTitle = 'Source: wikipedia.org';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Series overlap action
Use the seriesOverlapAction property in smartLabelSettings to specify whether labels can overlap the series elements, such as lines, areas, columns, bars, and trendlines.
-
None(default) - Labels avoid only other labels and markers, so they can be placed over series elements. -
Hide- Labels also avoid the elements of all visible series. A label moves to a free position if one exists, and is hidden only when none is available.
Note: In canvas rendering mode,
Hidebehaves likeNone.
import { ChartModule } from '@syncfusion/ej2-angular-charts';
import { LineSeriesService, LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
@Component({
imports: [
ChartModule
],
providers: [LineSeriesService, LegendService, DataLabelService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis' [enableSmartLabels]='true' [title]='title' [subTitle]='subTitle'>
<e-series-collection>
<e-series [dataSource]='vietnam' type='Line' xName='x' yName='y' name='Vietnam' width=2 [animation]='animation' [marker]='vietnamMarker'></e-series>
<e-series [dataSource]='indonesia' type='Line' xName='x' yName='y' name='Indonesia' width=2 [animation]='animation' [marker]='indonesiaMarker'></e-series>
<e-series [dataSource]='france' type='Line' xName='x' yName='y' name='France' width=2 [animation]='animation' [marker]='franceMarker'></e-series>
<e-series [dataSource]='poland' type='Line' xName='x' yName='y' name='Poland' width=2 [animation]='animation' [marker]='polandMarker'></e-series>
<e-series [dataSource]='mexico' type='Line' xName='x' yName='y' name='Mexico' width=2 [animation]='animation' [marker]='mexicoMarker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public title?: string;
public subTitle?: string;
public animation?: Object;
public vietnam?: Object[];
public indonesia?: Object[];
public france?: Object[];
public poland?: Object[];
public mexico?: Object[];
public vietnamMarker?: Object;
public indonesiaMarker?: Object;
public franceMarker?: Object;
public polandMarker?: Object;
public mexicoMarker?: Object;
ngOnInit(): void {
this.vietnam = [
{ x: 2016, y: 7.8 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 15.5 },
{ x: 2019, y: 17.5 },
{ x: 2020, y: 19.5 },
{ x: 2021, y: 23.0 },
{ x: 2022, y: 20.0 },
{ x: 2023, y: 19.0 },
{ x: 2024, y: 22.1 }
];
this.indonesia = [
{ x: 2016, y: 4.8 },
{ x: 2017, y: 5.2 },
{ x: 2018, y: 6.2 },
{ x: 2019, y: 7.8 },
{ x: 2020, y: 9.3 },
{ x: 2021, y: 14.3 },
{ x: 2022, y: 15.6 },
{ x: 2023, y: 16.0 },
{ x: 2024, y: 17.0 }
];
this.france = [
{ x: 2016, y: 14.6 },
{ x: 2017, y: 15.5 },
{ x: 2018, y: 15.4 },
{ x: 2019, y: 14.4 },
{ x: 2020, y: 11.6 },
{ x: 2021, y: 13.9 },
{ x: 2022, y: 12.1 },
{ x: 2023, y: 10.0 },
{ x: 2024, y: 10.8 }
];
this.poland = [
{ x: 2016, y: 8.9 },
{ x: 2017, y: 10.3 },
{ x: 2018, y: 10.8 },
{ x: 2019, y: 9.0 },
{ x: 2020, y: 7.9 },
{ x: 2021, y: 8.5 },
{ x: 2022, y: 7.4 },
{ x: 2023, y: 6.4 },
{ x: 2024, y: 7.1 }
];
this.mexico = [
{ x: 2016, y: 19.0 },
{ x: 2017, y: 20.0 },
{ x: 2018, y: 20.2 },
{ x: 2019, y: 18.4 },
{ x: 2020, y: 16.8 },
{ x: 2021, y: 18.5 },
{ x: 2022, y: 18.4 },
{ x: 2023, y: 16.3 },
{ x: 2024, y: 13.7 }
];
this.primaryXAxis = {
valueType: 'Double',
majorGridLines: { width: 0 },
edgeLabelPlacement: 'Shift'
};
this.primaryYAxis = {
title: 'Volume in million metric tons',
labelFormat: '{value}',
lineStyle: { width: 0 },
majorTickLines: { width: 0 },
minorTickLines: { width: 0 }
};
this.animation = { enable: false };
this.vietnamMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Circle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
this.indonesiaMarker = {
visible: true,
width: 6,
height: 6,
shape: 'Triangle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
this.franceMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Diamond',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
this.polandMarker = {
visible: true,
width: 5,
height: 5,
shape: 'Rectangle',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
this.mexicoMarker = {
visible: true,
width: 7,
height: 7,
shape: 'Pentagon',
isFilled: true,
dataLabel: {
visible: true,
smartLabelSettings: {
seriesOverlapAction: 'Hide'
}
}
};
this.title = 'Annual Crude Steel Production by Country (2016–2024)';
this.subTitle = 'Source: wikipedia.org';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Customizing Specific Point
Customize individual markers or labels using the pointRender and textRender events of the chart.
-
pointRendermodifies the shape, color, or border of a point. -
textRendercustomizes the label text for specific points.
Note: The event arguments for
pointRenderandtextRenderare typed asIPointRenderEventArgsandITextRenderEventArgsrespectively.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { IPointRenderEventArgs, ITextRenderEventArgs } from '@syncfusion/ej2-angular-charts';
import { columnData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, CategoryService ],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' (pointRender)='pointRender($event)' (textRender)='textRender($event)'[title]='title'>
<e-series-collection>
<e-series [dataSource]='chartData' type='Column' xName='x' yName='y' name='Warmest' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public marker?: Object;
primaryYAxis: any;
public pointRender(args: IPointRenderEventArgs): void {
if(args.point.index === 6) {
args.fill = 'red'
}
};
public textRender(args: ITextRenderEventArgs): void {
if(args.point.index === 6){
args.text = 'Maximum Temperature';
args.color = 'red';
}
};
ngOnInit(): void {
this.chartData = columnData;
this.primaryXAxis = {
title: 'Months',
valueType: 'Category', labelFormat: 'yMMM',
edgeLabelPlacement: 'Shift'
};
this.marker = { dataLabel: { visible: true }
};
this.title = 'Alaska Weather Statistics - 2016';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Show Percentage Based on Each Series Points
Calculate and display percentage values based on each series’ total using the seriesRender and textRender events.
- In
seriesRender, compute the total ofyvalues. - In
textRender, calculate the percentage for each point and update the label text.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CategoryService, LineSeriesService, ColumnSeriesService } from '@syncfusion/ej2-angular-charts'
import { LegendService, DataLabelService } from '@syncfusion/ej2-angular-charts'
import { Component, ViewEncapsulation } from '@angular/core';
import {
ISeriesRenderEventArgs,
ITextRenderEventArgs,
} from '@syncfusion/ej2-angular-charts';
import { Browser } from '@syncfusion/ej2-base';
let total: any = [];
/**
* Sample for Column Series
*/
@Component({
imports: [
ChartModule
],
providers: [ DateTimeService, LineSeriesService, LegendService, DataLabelService, ColumnSeriesService, CategoryService ],
standalone: true,
selector: 'app-container',
template: `<div class="control-section">
<div align='center'>
<ejs-chart style='display:block;' [chartArea]='chartArea' [width]='width' align='center' id='chartcontainer' [primaryXAxis]='primaryXAxis'
[primaryYAxis]='primaryYAxis' [title]='title' [tooltip]='tooltip' (seriesRender)='seriesRender($event)' (textRender)='textRender($event)'>
<e-series-collection>
<e-series [dataSource]='data' type='Column' xName='x' yName='y' name='Gold' width=2 [marker]='marker'> </e-series>
<e-series [dataSource]='data1' type='Column' xName='x' yName='y' name='Silver' width=2 [marker]='marker'> </e-series>
<e-series [dataSource]='data2' type='Column' xName='x' yName='y' name='Bronze' width=2 [marker]='marker'> </e-series>
</e-series-collection>
</ejs-chart>
</div>
<div style="float: right; margin-right: 10px; margin-top: -5px">Source:
<a href="https://www.gov.uk/" target='_blank'>www.gov.uk</a>
</div>
</div>`,
encapsulation: ViewEncapsulation.None,
})
export class AppComponent {
public data: Object[] = [
{ x: 'USA', y: 46 },
{ x: 'GBR', y: 27 },
{ x: 'CHN', y: 26 },
];
public data1: Object[] = [
{ x: 'USA', y: 37 },
{ x: 'GBR', y: 23 },
{ x: 'CHN', y: 18 },
];
public data2: Object[] = [
{ x: 'USA', y: 38 },
{ x: 'GBR', y: 17 },
{ x: 'CHN', y: 26 },
];
//Initializing Primary X Axis
public primaryXAxis: Object = {
valueType: 'Category',
interval: 1,
majorGridLines: { width: 0 },
};
//Initializing Primary Y Axis
public primaryYAxis: Object = {
majorGridLines: { width: 0 },
majorTickLines: { width: 0 },
lineStyle: { width: 0 },
labelStyle: { color: 'transparent' },
};
public marker: Object = {
dataLabel: {
visible: true,
position: 'Top',
font: { fontWeight: '600', color: '#ffffff' },
},
};
public title: string = 'Olympic Medal Counts - RIO';
public tooltip: Object = {
enable: true,
};
// custom code start
public seriesRender(args: ISeriesRenderEventArgs | any): void {
for (let i = 0; i < args.data.length; i++) {
if (!total[args.data[i].x]) total[args.data[i].x] = 0;
total[args.data[i].x] += parseInt(args.data[i].y);
}
}
public textRender(args: ITextRenderEventArgs | any): void {
let percentage: number | string = (parseInt(args.text) / total[args.point.x]) * 100;
percentage = percentage % 1 === 0 ? percentage : percentage.toFixed(2);
args.text = percentage + '%';
}
// custom code end
public chartArea: Object = {
border: {
width: 0,
},
};
public width: string = Browser.isDevice ? '100%' : '60%';
constructor() {
//code
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Last Value Label
The lastValueLabel in a chart allows you to easily display the value of the last data point in a series. This feature provides an intuitive way to highlight the most recent or last data value in a series on your chart.
Enable Last Value Label
To show the last value label, make sure the enable property inside the lastValueLabel settings is set to true within the series configuration.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import {
ColumnSeriesService, DataLabelService, CategoryService, LegendService, TooltipService, LastValueLabelService
} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
@Component({
imports: [
ChartModule
],
providers: [ColumnSeriesService, DataLabelService, CategoryService, LegendService, TooltipService, LastValueLabelService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis' [title]='title' [tooltip]='tooltip' [width]='width'>
<e-series-collection>
<e-series [dataSource]='chartData' type='Column' xName='x' yName='y' name='series1' [marker]='marker' [lastValueLabel]='lastValueLabel'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public title?: string;
public width?: string;
public tooltip?: Object;
public lastValueLabel?: Object;
public chartData?: Object[];
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 40 }
];
this.lastValueLabel = { enable: true };
this.width = '90%';
this.primaryXAxis = {
title: 'Year',
interval: 1
};
this.primaryYAxis = {
title: 'Efficiency',
labelFormat: '{value}%'
};
this.tooltip = { enable: true };
this.marker = { visible: false, dataLabel: { visible: true } };
this.title = 'Efficiency of oil-fired power production';
}
}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 Last Value Label feature, inject
LastValueLabelServiceinto the@NgModule.providers.
Customization
The appearance of the last value label can be customized using style properties such as font, background, border, dashArray, lineWidth, lineColor, rx, and ry in the lastValueLabel property of the chart series. These settings allow you to tailor the label’s look to align with your desired visual presentation.
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import {
ColumnSeriesService, DataLabelService, CategoryService, LegendService, TooltipService, LastValueLabelService
} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
@Component({
imports: [
ChartModule
],
providers: [ColumnSeriesService, DataLabelService, CategoryService, LegendService, TooltipService, LastValueLabelService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis' [primaryYAxis]='primaryYAxis' [title]='title' [tooltip]='tooltip' [width]='width'>
<e-series-collection>
<e-series [dataSource]='chartData' type='Column' xName='x' yName='y' name='series1' [marker]='marker' [lastValueLabel]='lastValueLabel'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public title?: string;
public width?: string;
public tooltip?: Object;
public lastValueLabel?: Object;
public chartData?: Object[];
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public marker?: Object;
ngOnInit(): void {
this.chartData = [
{ x: 2005, y: 28 }, { x: 2006, y: 25 }, { x: 2007, y: 26 }, { x: 2008, y: 27 },
{ x: 2009, y: 32 }, { x: 2010, y: 35 }, { x: 2011, y: 40 }
];
this.lastValueLabel = { enable: true, background: "blue", lineColor: "red", lineWidth: 2, dashArray: "5,5", rx: 10, ry: 10, border: { width: 2, color: "red" }, font: { color: "white", size: "12px", fontWeight: "bold" } };
this.width = '90%';
this.primaryXAxis = {
title: 'Year',
interval: 1
};
this.primaryYAxis = {
title: 'Efficiency',
labelFormat: '{value}%'
};
this.tooltip = { enable: true };
this.marker = { visible: false, dataLabel: { visible: true } };
this.title = 'Efficiency of oil-fired power production';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Prevent Data Label
Hide data labels for points whose value is 0 using the textRender event. In the handler, check args.point.y and set args.cancel to true when it equals 0.
import { ChartModule, ChartAllModule, AccumulationChartAllModule } from '@syncfusion/ej2-angular-charts'
import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts'
import { PieSeriesService, AccumulationTooltipService, AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts'
import {
LineSeriesService, DateTimeService, DataLabelService, StackingColumnSeriesService, CategoryService,
StepAreaSeriesService, SplineSeriesService, ScrollBarService, ChartAnnotationService, LegendService, TooltipService, StripLineService,
SelectionService, ScatterSeriesService, ZoomService, ColumnSeriesService, AreaSeriesService, RangeAreaSeriesService
} from '@syncfusion/ej2-angular-charts'
import { Component, OnInit } from '@angular/core';
import { ITextRenderEventArgs } from '@syncfusion/ej2-angular-charts';
@Component({
imports: [
ChartModule, ChartAllModule, AccumulationChartAllModule, AccumulationChartModule
],
providers: [LineSeriesService, DateTimeService, ColumnSeriesService, DataLabelService, ZoomService, StackingColumnSeriesService, CategoryService,
StepAreaSeriesService, SplineSeriesService, ChartAnnotationService, LegendService, TooltipService, StripLineService,
PieSeriesService, AccumulationTooltipService, ScrollBarService, AccumulationDataLabelService, SelectionService, ScatterSeriesService,
AreaSeriesService, RangeAreaSeriesService ],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title' (textRender)='textRender($event)'>
<e-series-collection>
<e-series [dataSource]='chartData' type='Line' xName='x' yName='y' name='India' width=2 [marker]='marker'></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public chartData?: Object[];
public title?: string;
public marker?: Object;
public primaryYAxis?: Object;
public textRender(args: ITextRenderEventArgs): void {
if (args.text === '0') {
args.cancel = args.point.y === 0;
}
};
ngOnInit(): void {
this.chartData = [
{ x: new Date(2005, 0, 1), y: 21 }, { x: new Date(2006, 0, 1), y: 24 },
{ x: new Date(2007, 0, 1), y: 0 }, { x: new Date(2008, 0, 1), y: 38 },
{ x: new Date(2009, 0, 1), y: 54 }, { x: new Date(2010, 0, 1), y: 57 },
];
this.primaryXAxis = {
title: 'Year',
valueType: 'DateTime'
};
this.primaryYAxis = {
title: 'Efficiency',
};
this.marker = { visible: true, width: 10, height: 10, dataLabel: { visible: true}};
this.title = 'Inflation - Consumer Price';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));