Labels in Angular Sankey component
18 Nov 201817 minutes to read
Labels display descriptive text associated with nodes in the Sankey diagram, improving readability and interpretation. Additionally, labels make the diagram more understandable and interpretable, and the component provides comprehensive label customization options including visibility control, font styling, individual label configuration, and dynamic rendering events.
This guide covers label appearance configuration, visibility control, font styling, and advanced label customization.
Label Settings Properties
The labelSettings property provides options to control label appearance, text styling, and visibility. These properties apply globally to all node labels.
Label Configuration Properties
| Property | Type | Default | Description |
|---|---|---|---|
| visible | boolean | true | Shows or hides node labels. |
| fontSize | string \ number | ‘12px’ | Font size for labels. |
| color | string | ’’ | Text color for labels. |
| fontFamily | string | null | Font family for label text. |
| fontWeight | string | ‘400’ | Font weight (e.g., ‘700’ for bold). |
| fontStyle | string | ‘normal’ | Font style (e.g., ‘italic’). |
| padding | number | 10 | Padding around label text. |
Configure global label styling for all nodes by setting properties like font size, color, font family, and font weight
Here is an example of customizing label appearance:
// app.component.ts
import { Component } from '@angular/core';
import {
SankeyAllModule,
SankeyTooltipService,
SankeyLegendService
} from '@syncfusion/ej2-angular-charts';
@Component({
standalone: true,
selector: 'app-container',
imports: [SankeyAllModule],
providers: [SankeyTooltipService, SankeyLegendService],
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[labelSettings]="labelSettings"
[tooltip]="tooltip"
[legendSettings]="legendSettings">
<e-sankey-nodes>
<e-sankey-node id="Agricultural Waste"></e-sankey-node>
<e-sankey-node id="Biomass Residues"></e-sankey-node>
<e-sankey-node id="Bio-conversion"></e-sankey-node>
<e-sankey-node id="Liquid Biofuel"></e-sankey-node>
<e-sankey-node id="Electricity"></e-sankey-node>
<e-sankey-node id="Heat"></e-sankey-node>
</e-sankey-nodes>
<e-sankey-links>
<e-sankey-link sourceId="Agricultural Waste" targetId="Bio-conversion" [value]="84.152"></e-sankey-link>
<e-sankey-link sourceId="Biomass Residues" targetId="Bio-conversion" [value]="24.152"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Liquid Biofuel" [value]="10.597"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Electricity" [value]="36.862"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Heat" [value]="60.845"></e-sankey-link>
</e-sankey-links>
</ejs-sankey>
</div>
</div>
`
})
export class AppComponent {
public labelSettings = {
visible: true,
fontFamily: 'Segoe UI',
fontStyle: 'normal',
fontWeight: 'bold',
fontSize: '14px',
color: '#333'
};
public tooltip = {
enable: true
};
public legendSettings = {
visible: true
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Hiding Labels
Set labelSettings.visible to false to hide labels when space is limited. Additionally: hiding labels can be useful for creating cleaner visualizations when labels take up too much space.
// app.component.ts
import { Component } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService
} from '@syncfusion/ej2-angular-charts';
@Component({
standalone: true,
selector: 'app-container',
imports: [SankeyAllModule],
providers: [SankeyTooltipService, SankeyLegendService],
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[labelSettings]="labelSettings"
[tooltip]="tooltip"
[legendSettings]="legendSettings">
<e-sankey-nodes>
<e-sankey-node id="Agricultural Waste"></e-sankey-node>
<e-sankey-node id="Biomass Residues"></e-sankey-node>
<e-sankey-node id="Bio-conversion"></e-sankey-node>
<e-sankey-node id="Liquid Biofuel"></e-sankey-node>
<e-sankey-node id="Electricity"></e-sankey-node>
<e-sankey-node id="Heat"></e-sankey-node>
</e-sankey-nodes>
<e-sankey-links>
<e-sankey-link sourceId="Agricultural Waste" targetId="Bio-conversion" [value]="84.152"></e-sankey-link>
<e-sankey-link sourceId="Biomass Residues" targetId="Bio-conversion" [value]="24.152"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Liquid Biofuel" [value]="10.597"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Electricity" [value]="36.862"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Heat" [value]="60.845"></e-sankey-link>
</e-sankey-links>
</ejs-sankey>
</div>
</div>
`
})
export class AppComponent {
public labelSettings = {
visible: false
};
public tooltip = {
enable: true
};
public legendSettings = {
visible: true
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Font Styling
Apply custom font styling to all labels using properties such as:
-
fontSize: Adjust text size (e.g., ‘12px’, ‘14px’) -
fontFamily: Specify font family (e.g., ‘Arial’, ‘Times New Roman’) -
fontWeight: Control text thickness (‘400’ = normal, ‘700’ = bold) -
fontStyle: Apply text styling (‘normal’ or ‘italic’) -
color: Set text color (hex or color names)
// app.component.ts
import { Component } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService
} from '@syncfusion/ej2-angular-charts';
@Component({
standalone: true,
selector: 'app-container',
imports: [SankeyAllModule],
providers: [SankeyTooltipService, SankeyLegendService],
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[labelSettings]="labelSettings"
[tooltip]="tooltip"
[legendSettings]="legendSettings">
<e-sankey-nodes>
<e-sankey-node id="Agricultural Waste"></e-sankey-node>
<e-sankey-node id="Biomass Residues"></e-sankey-node>
<e-sankey-node id="Bio-conversion"></e-sankey-node>
<e-sankey-node id="Liquid Biofuel"></e-sankey-node>
<e-sankey-node id="Electricity"></e-sankey-node>
<e-sankey-node id="Heat"></e-sankey-node>
</e-sankey-nodes>
<e-sankey-links>
<e-sankey-link sourceId="Agricultural Waste" targetId="Bio-conversion" [value]="84.152"></e-sankey-link>
<e-sankey-link sourceId="Biomass Residues" targetId="Bio-conversion" [value]="24.152"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Liquid Biofuel" [value]="10.597"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Electricity" [value]="36.862"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Heat" [value]="60.845"></e-sankey-link>
</e-sankey-links>
</ejs-sankey>
</div>
</div>
`
})
export class AppComponent {
public labelSettings = {
visible: true,
fontFamily: 'Times New Roman',
fontStyle: 'italic',
fontWeight: 'bold',
fontSize: '16px',
color: '#C00'
};
public tooltip = {
enable: true
};
public legendSettings = {
visible: true
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Individual Node Labels
Customize the appearance of specific node labels by configuring the label property on each node object. This allows you to override global label settings for specific nodes, enabling data-driven label customization:
// app.component.ts
import { Component } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService
} from '@syncfusion/ej2-angular-charts';
@Component({
standalone: true,
selector: 'app-container',
imports: [SankeyAllModule],
providers: [SankeyTooltipService, SankeyLegendService],
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[labelSettings]="labelSettings"
[tooltip]="tooltip"
[legendSettings]="legendSettings">
<e-sankey-nodes>
<e-sankey-node id="Agricultural Waste" color="#f41212"></e-sankey-node>
<e-sankey-node id="Biomass Residues" color="#aed62c"></e-sankey-node>
<e-sankey-node id="Bio-conversion" color="#259bc3"></e-sankey-node>
<e-sankey-node id="Liquid Biofuel" color="#0e11af"></e-sankey-node>
<e-sankey-node id="Electricity" color="#7a0e92"></e-sankey-node>
<e-sankey-node id="Heat" color="#c5b9bb"></e-sankey-node>
</e-sankey-nodes>
<e-sankey-links>
<e-sankey-link sourceId="Agricultural Waste" targetId="Bio-conversion" [value]="84.152"></e-sankey-link>
<e-sankey-link sourceId="Biomass Residues" targetId="Bio-conversion" [value]="24.152"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Liquid Biofuel" [value]="10.597"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Electricity" [value]="36.862"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Heat" [value]="60.845"></e-sankey-link>
</e-sankey-links>
</ejs-sankey>
</div>
</div>
`
})
export class AppComponent {
public labelSettings = {
visible: true
};
public tooltip = {
enable: true
};
public legendSettings = {
visible: true
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Advanced Label Configuration
Dynamic Label Customization
Use the labelRendering event to customize each label dynamically before rendering. Additionally: this event triggers for each label before drawing, allowing conditional formatting, modifying text, or adjusting label styling based on data values.
// app.component.ts
import { Component } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService
} from '@syncfusion/ej2-angular-charts';
import { SankeyLabelRenderEventArgs } from '@syncfusion/ej2-angular-charts';
@Component({
standalone: true,
selector: 'app-container',
imports: [SankeyAllModule],
providers: [SankeyTooltipService, SankeyLegendService],
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[labelSettings]="labelSettings"
[tooltip]="tooltip"
[legendSettings]="legendSettings"
(labelRendering)="onLabelRendering($event)">
<e-sankey-nodes>
<e-sankey-node id="Agricultural Waste"></e-sankey-node>
<e-sankey-node id="Biomass Residues"></e-sankey-node>
<e-sankey-node id="Bio-conversion"></e-sankey-node>
<e-sankey-node id="Liquid Biofuel"></e-sankey-node>
<e-sankey-node id="Electricity"></e-sankey-node>
<e-sankey-node id="Heat"></e-sankey-node>
</e-sankey-nodes>
<e-sankey-links>
<e-sankey-link sourceId="Agricultural Waste" targetId="Bio-conversion" [value]="84.152"></e-sankey-link>
<e-sankey-link sourceId="Biomass Residues" targetId="Bio-conversion" [value]="24.152"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Liquid Biofuel" [value]="10.597"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Electricity" [value]="36.862"></e-sankey-link>
<e-sankey-link sourceId="Bio-conversion" targetId="Heat" [value]="60.845"></e-sankey-link>
</e-sankey-links>
</ejs-sankey>
</div>
</div>
`
})
export class AppComponent {
public labelSettings = {
visible: true
};
public tooltip = {
enable: true
};
public legendSettings = {
visible: true
};
onLabelRendering(args:SankeyLabelRenderEventArgs): void {
if (args.text ==="Agricultural Waste 84.152") {
args.labelStyle.fontWeight = 'bold';
args.labelStyle.color = '#FF6B6B';
args.labelStyle.fontSize = '14px';
}
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));