Print and Export in EJ2 TypeScript 3D Chart control
10 Jan 20247 minutes to read
The rendered 3D chart can be printed directly from the browser by calling the public method print. The ID of the 3D chart’s div element must be passed as the input parameter to that method.
import {Chart3D, Category3D, Legend3D, ColumnSeries3D, Tooltip3D, Highlight3D } from '@syncfusion/ej2-charts';
Chart3D.Inject(ColumnSeries3D, Category3D, Legend3D, Tooltip3D, Highlight3D);
let chartData: any[] = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
let chart: Chart3D = new Chart3D({
primaryXAxis: {
valueType: 'Category',
},
series:[{
dataSource: chartData,
xName: 'country', yName: 'gold',
name: 'Gold', type: 'Column'
}],
title: 'Olympic Medals',
wallColor: 'transparent',
enableRotation: true,
rotation: 7,
tilt: 10,
depth: 100
}, '#element');
document.getElementById('print').onclick = () => {
chart.print();
};<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
<button id= "print" type="button" width ='15%' style="float: right">Print</button>
</div>
</body>
</html>Export
The rendered 3D chart can be exported to JPEG, PNG, SVG, or PDF format using the export method. The input parameters for this method are: type for format and fileName for result.
import { DataLabel3D, Chart3D, Category3D, Legend3D, ColumnSeries3D, Tooltip3D, Highlight3D, Selection3D, Export3D} from '@syncfusion/ej2-charts';
Chart3D.Inject(ColumnSeries3D, Category3D, DataLabel3D, Legend3D, Tooltip3D, Highlight3D, Selection3D, Export3D);
let chartData: any[] = [
{ country: "USA", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
let chart: Chart3D = new Chart3D({
primaryXAxis: {
valueType: 'Category',
},
series:[{
dataSource: chartData,
xName: 'country', yName: 'gold',
name: 'Gold', type: 'Column'
}],
title: 'Olympic Medals',
wallColor: 'transparent',
enableRotation: true,
rotation: 7,
tilt: 10,
depth: 100
}, '#element');
document.getElementById('export').onclick = () => {
chart.export('PNG', 'result');
};<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
<button id= "export" type="button" width ='15%' style="float: right">Export</button>
</div>
</body>
</html>