ToolTip in Angular Sankey component
25 Mar 202612 minutes to read
The Sankey Chart provides tooltips that surface contextual details for hovered elements without cluttering the diagram. Tooltips display additional information when users hover over nodes or links in the Sankey Chart. You can enable and customize tooltips using the tooltip property and by injecting the SankeyTooltip module.
This guide outlines how to enable and customize tooltips in the React Sankey Chart.
Tooltip Settings Properties
The following table lists the main tooltip configuration properties:
| Property | Type | Default | Description |
|---|---|---|---|
| enable | boolean | true | Enables or disables the tooltip display. |
| fill | string | null | Background fill color of the tooltip. |
| opacity | number | 0.75 | Opacity of the tooltip container (0 to 1). |
| textStyle | object | null | Text styling for the tooltip content. |
| nodeFormat | string | ‘$name : $value’ | Format string for node tooltips. |
| linkFormat | string | ‘$start.name $start.value → $target.name $target.value’ | Format string for link tooltips. |
| enableAnimation | boolean | true | Toggles tooltip animation. |
| duration | number | 300 | Animation duration in milliseconds. |
| fadeOutDuration | number | 1000 | Fade-out duration in milliseconds. |
| fadeOutMode | string | ‘Move’ | Fade-out animation mode (‘Move’, ‘Fade’, ‘Delay’). |
Basic Tooltip Configuration
Enable tooltips with default formatting.
import { Component } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
} from '@syncfusion/ej2-angular-charts';
@Component({
imports: [SankeyAllModule],
providers: [
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
],
standalone: true,
selector: 'app-container',
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[tooltip]=tooltip>
<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 tooltip={ enable: true };
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Customizing Tooltip Appearance
Adjust tooltip appearance and behavior using tooltip configuration properties:
- Enable: Shows or hides tooltips.
- Fill: Sets background color.
- Opacity: Controls transparency (0 to 1). The default value is 0.75.
- TextStyle: Configures font size, family, weight, and color for the tooltip text.
- EnableAnimation: Toggles animation. Default: true.
- Duration: Animation duration in milliseconds. The default value is 300.
- FadeOutDuration: Fade-out duration in milliseconds. The default value is 1000.
Example customization:
import { Component } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
} from '@syncfusion/ej2-angular-charts';
@Component({
imports: [SankeyAllModule],
providers: [
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
],
standalone: true,
selector: 'app-container',
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[tooltip]="tooltipConfig">
<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 tooltipConfig = {
enable: true,
textStyle: {
fontFamily: 'Arial',
fontStyle: 'normal',
fontWeight: '500',
size: '14px',
color: '#000'
},
fill: '#F3F3F3',
border: {
color: '#666',
width: 1
}
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Format Strings
Format strings provide a simple way to customize tooltip content without custom templates.
Node Tooltip Format
Format string placeholders for node tooltips:
-
$name– Node label -
$value– Node value (sum of incoming links)
Link Tooltip Format
Format string placeholders for link tooltips:
-
$start.name– Source node label -
$start.value– Source node value -
$target.name– Target node label -
$target.value– Target node value -
$value– Link value
Example with custom format strings:
import { Component } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
} from '@syncfusion/ej2-angular-charts';
@Component({
imports: [SankeyAllModule],
providers: [
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
],
standalone: true,
selector: 'app-container',
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[tooltip]="tooltipConfig">
<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 tooltipConfig = {
enable: true,
nodeTemplate: '${name}: ${value} TBtu',
linkTemplate: '${start.name}: ${start.out} TBtu → ${target.name}: ${target.in} TBtu'
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Advanced Tooltip Configuration
Tooltip Rendering Event
Use tooltipRendering to programmatically modify tooltip content before display.
import { Component } from '@angular/core';
import { SankeyAllModule, SankeyTooltipRenderEventArgs } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
} from '@syncfusion/ej2-angular-charts';
@Component({
imports: [SankeyAllModule],
providers: [
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
],
standalone: true,
selector: 'app-container',
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<ejs-sankey
width="90%"
height="450px"
[tooltip]="{ enable: true }"
(tooltipRendering)="onTooltipRender($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 {
onTooltipRender(args: SankeyTooltipRenderEventArgs): void {
if (args.link) {
args.text = `Flow: ${args.link.sourceId} → ${args.link.targetId} (${args.link.value})`;
} else if (args.node) {
args.text = `Node: ${args.node.id}`;
}
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Disabling Tooltips
To disable tooltips:
const tooltip = { enable: false };Key Considerations
- Keep Text Concise: Keep tooltip text concise and readable.
- Ensure Contrast: Ensure sufficient contrast for tooltip text and background.
-
Use Format Strings: Prefer
nodeFormatandlinkFormatfor simple content customization without requiring custom rendering logic. - Animation Tuning: Tune animation durations to balance responsiveness and polish.
- Performance: Use format strings instead of complex rendering logic for better performance.
- Relevant Information: Show only relevant and helpful information.
- Consistent Styling: Maintain consistent tooltip styling across your application.