Search results

Print and Export in JavaScript Circular Gauge control

19 Oct 2021 / 3 minutes to read

Print

To use the print functionality, we should inject the Print module and set the allowPrint property to true. The rendered circular gauge can be printed directly from the browser by calling the method print.

Source
Preview
index.ts
index.html
Copied to clipboard
import { CircularGauge, Print } from '@syncfusion/ej2-circulargauge';
CircularGauge.Inject(Print);

let gauge: CircularGauge = new CircularGauge({
    allowPrint: true
});
gauge.appendTo('#element');
document.getElementById('print').onclick = () => {
    gauge.print();
};
Copied to clipboard
<!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" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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

Image Export

To use the image export functionality, we should inject the ImageExport module and set the allowImageExport property to true. The rendered circular gauge can be exported as an image using the export method. The method requires two parameters: image type and file name. The circular gauge can be exported as an image in the following formats.

  • JPEG
  • PNG
  • SVG
Source
Preview
index.ts
index.html
Copied to clipboard
import { CircularGauge, ImageExport} from '@syncfusion/ej2-circulargauge';
CircularGauge.Inject(ImageExport);

let gauge: CircularGauge = new CircularGauge({
allowImageExport: true
});
gauge.appendTo('#element');
document.getElementById('export').onclick = () => {
gauge.export("PNG","Gauge");
};
Copied to clipboard
<!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" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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 id="data"></div>
    </div>
</body>

</html>

We can get the image file as base64 string for the JPEG and PNG formats. The circular gauge can be exported to image as a base64 string using the export method. There are four parameters required: image type, file name, orientation of the exported PDF document which must be set as null for image export and finally allowDownload which should be set as false to return base64 string.

Source
Preview
index.ts
index.html
Copied to clipboard
import { CircularGauge, ImageExport } from '@syncfusion/ej2-circulargauge';
CircularGauge.Inject(ImageExport);

let gauge: CircularGauge = new CircularGauge({
allowImageExport: true
});
gauge.appendTo('#element');
document.getElementById('export').onclick = () => {
gauge.export('JPEG', 'Gauge', null, false).then((data) => {
        document.getElementById('data').innerHTML = data;
    });
};
Copied to clipboard
<!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" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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 id="data"></div>
    </div>
</body>

</html>

PDF Export

To use the PDF export functionality, we should inject the PdfExport module and set the allowPdfExport property to true. The rendered circular gauge can be exported as PDF using the export method. The export method requires three parameters: file type, file name and orientation of the PDF document. The orientation setting is optional and “0” indicates portrait and “1” indicates landscape.

Source
Preview
index.ts
index.html
Copied to clipboard
import { CircularGauge, PdfExport } from '@syncfusion/ej2-circulargauge';
CircularGauge.Inject(PdfExport);

let gauge: CircularGauge = new CircularGauge({
allowPdfExport: true
});
gauge.appendTo('#element');
document.getElementById('export').onclick = () => {
gauge.export("PDF", "Gauge");
};
Copied to clipboard
<!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" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></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 id="data"></div>
    </div>
</body>

</html>

Note: The exporting of the circular gauge as base64 string is not supported in the PDF export.