Print and Export in Angular Sankey component
18 Nov 201818 minutes to read
The Sankey Chart provides comprehensive print and export functionality, enabling users to generate static files in multiple formats (PNG, JPEG, SVG, PDF) or print the diagram directly. This is useful for reports, documentation, sharing, and offline access.
This guide covers printing the chart and exporting to various formats with customization options.
Print the Sankey Chart directly to paper or PDF using the print() method. This opens the browser’s print dialog, allowing users to select printer settings and output format:
import { Component, ViewChild } from '@angular/core';
import { SankeyAllModule, SankeyComponent } from '@syncfusion/ej2-angular-charts';
import {
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
} from '@syncfusion/ej2-angular-charts';
@Component({
imports: [SankeyAllModule],
providers: [
SankeyTooltipService,
SankeyLegendService,
SankeyExportService // required for print/export features
],
standalone: true,
selector: 'app-container',
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<button (click)="printChart()" style="margin-bottom: 10px;">
Print
</button>
<ejs-sankey
#sankeyChart
id="sankey-container"
width="90%"
height="450px">
<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 {
@ViewChild('sankeyChart') sankeyChart?: SankeyComponent;
printChart() {
if (this.sankeyChart) {
this.sankeyChart.print();
}
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Export
Export the Sankey Chart to various file formats using the export() method. This allows you to generate standalone files suitable for sharing, archiving, or embedding in documents.
Export Formats
The Sankey Chart supports exporting to the following formats:
- PNG - Portable Network Graphics (raster format, good for web)
- JPEG - Joint Photographic Experts Group (compressed raster, smaller file size)
- SVG - Scalable Vector Graphics (vector format, scalable without quality loss)
- PDF - Portable Document Format (ideal for printing and archiving)
Export with Default Settings
Export the chart using default settings with a default filename:
import { Component, ViewChild } from '@angular/core';
import { SankeyAllModule, SankeyComponent } 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">
<button (click)="exportPNG()" style="margin-right: 5px;">Export PNG</button>
<button (click)="exportPDF()" style="margin-right: 5px;">Export PDF</button>
<button (click)="exportSVG()" style="margin-bottom: 10px;">Export SVG</button>
<ejs-sankey
#sankeyChart
id="sankey-container"
width="90%"
height="450px">
<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 {
@ViewChild('sankeyChart') sankeyChart?: SankeyComponent;
exportPNG() {
if (this.sankeyChart) {
this.sankeyChart.export('PNG', 'Sankey');
}
}
exportPDF() {
if (this.sankeyChart) {
this.sankeyChart.export('PDF', 'Sankey');
}
}
exportSVG() {
if (this.sankeyChart) {
this.sankeyChart.export('SVG', 'Sankey');
}
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Export with Custom Options
Export the chart with a custom filename and format selection to control output file names and type:
import { Component, ViewChild } 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">
<button (click)="handleCustomExport()" style="margin-bottom:10px">Export with Custom Options</button>
<ejs-sankey width="90%" height="450px">
<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 {
@ViewChild('sankey') public sankeyObj: any;
public handleCustomExport(): void {
this.sankeyObj?.export('PNG', 'CustomSankey', 0, true);
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Export Events
Before Export Event
Use the beforeExport event to customize the export process before the file is generated. This allows you to modify chart properties, add watermarks, or perform pre-export calculation
Use the beforeExport event to customize the export process:
// app.component.ts
import { Component, ViewChild } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyComponent,
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
} from '@syncfusion/ej2-angular-charts';
import { SankeyExportEventArgs } from '@syncfusion/ej2-angular-charts';
@Component({
standalone: true,
selector: 'app-container',
imports: [SankeyAllModule],
providers: [
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
],
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<button (click)="exportChart()" style="margin-bottom: 10px;">
Export PNG
</button>
<ejs-sankey
width="90%"
height="450px"
(beforeExport)="beforeExport($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>
`,
styles: [`
.control-pane { padding: 20px; }
.control-section { max-width: 1400px; margin: 0 auto; }
`]
})
export class AppComponent {
@ViewChild('sankeyChart') sankeyChart!: SankeyComponent;
public tooltip = {
enable: true
};
public legendSettings = {
visible: true
};
beforeExport(args:SankeyExportEventArgs): void {
args.cancel = false;
}
exportChart(): void {
if (this.sankeyChart) {
this.sankeyChart.export('PNG', 'Sankey');
}
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Export Completed Event
Handle the completion of the export using the exportCompleted event.
// app.component.ts
import { Component, ViewChild } from '@angular/core';
import { SankeyAllModule } from '@syncfusion/ej2-angular-charts';
import {
SankeyComponent,
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
} from '@syncfusion/ej2-angular-charts';
@Component({
standalone: true,
selector: 'app-container',
imports: [SankeyAllModule],
providers: [
SankeyTooltipService,
SankeyLegendService,
SankeyExportService
],
template: `
<div class="control-pane">
<div class="control-section" id="sankey-container">
<button (click)="exportCustom()" style="margin-bottom: 10px;">
Export
</button>
<ejs-sankey
width="90%"
height="450px"
>
<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>
`,
styles: [`
.control-pane { padding: 20px; }
.control-section { max-width: 1400px; margin: 0 auto; }
`]
})
export class AppComponent {
@ViewChild('sankeyChart') sankeyChart!: SankeyComponent;
public tooltip = {
enable: true
};
public legendSettings = {
visible: true
};
exportCustom(): void {
if (this.sankeyChart) {
this.sankeyChart.export('PNG', 'CustomSankey');
}
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Export Format Comparison
| Format | Use Case | Quality | File Size |
|---|---|---|---|
| PNG | Web sharing, presentations | Raster (good quality) | Medium |
| JPEG | Web images, email | Raster (good quality) | Small |
| SVG | Scalable graphics, printing | Vector (scalable) | Medium |
| Documents, archival | Vector (scalable) | Medium |
Best Practices
- PNG/JPEG: Best for quick sharing and web usage.
- SVG: Best for scalable, print-ready exports.
- PDF: Best for formal documents and archival purposes.
- Choose the export format based on distribution and usage needs.
- Test exports in different formats to ensure the output quality meets expectations.