Export SfCircularGauge to memory stream

I'm trying to export a SfCircularGauge to a memorystream to allow the gauge image to be embedded into a generated excel document. I've done this for SfCharts using the OnExportComplete event but this event does not appear to exist on the SfCircularGauge.

Can you tell how I can get the SfCircularGauge  image into a memory stream?

3 Replies 1 reply marked as answer

SA Sabari Anand Senthamarai Kannan Syncfusion Team March 26, 2021 12:39 PM UTC

Hi Michael, 
 
Thank you for contacting Syncfusion support. 
 
We do not have support for OnExportComplete event in the Circular Gauge. But we support returning base64 string of the exported image when the Export() method is called. The Export() method has the following parameters to pass. 
 
1.       Type of the extension for export such as PNG, JPEG, SVG and PDF. For image export, we need to enable the AllowImageExport property by setting the value as "true" in the SfCircularGauge class.  
2.       The name of the exported file. Since you need to get the file as base64 string, this parameter can be empty. 
3.       The orientation of the PDF file, if we need to export to PDF file. This parameter can be “null” for your requirement. 
4.       A Boolean value “allowDownload” must be passed. If the value is true, the exported file will be downloaded. If the value is false, the exported file will be returned as base64 string.  
 
Once the exported image file is returned as base64 string, we can convert it into byte array. This byte array can be converted into stream. The stream of the image can be used to add in the Excel file. Please find the code snippet for the getting the base64 string of the exported image file of Circular Gauge below. 
 
Code Snippet
    string exportString = await gauge.Export(ExportType.JPEG, string.Empty, null, false); 
    exportString = exportString.Split("data:image/jpeg;base64,")[1]; 
    byte[] byteArray = Convert.FromBase64String(exportString); 
    using (MemoryStream memoryStream = new MemoryStream(byteArray)) 
   
         // Excel conversion code. 
   
 
We can add the image to the Excel document using our Syncfusion XlsIO library. Please find the documentation link to add the images in the Excel document for your reference below. 
 
 
We have created a sample application to demonstrate the same and it can be downloaded from the below link. 
 
 
In the above sample application, the Circular Gauge is export as image and saved to the Excel document. The Excel document will be available in the “wwwroot” folder of the application. 
 
Please let us know if the above sample meets your requirement. 
 
Regards, 
Sabari Anand

Marked as answer

MA Michael Aston March 26, 2021 02:27 PM UTC

That's great. Thanks


SA Sabari Anand Senthamarai Kannan Syncfusion Team March 29, 2021 05:52 AM UTC

Hi Michael, 
 
Thank you for your update.  
 
We are glad to hear that the provided solution meets your requirement. Please let us know if you need any further assistance. 
 
Regards, 
Sabari Anand 


Loader.
Up arrow icon