We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Export Chart as jpeg to a binary field

Hi,


We use in our program the possibility to export different charts. These are nicely downloaded in the browser.
Is it also possible to export charts as binary data? This way we could store the image in a separate database.

Thanks and regards,


Bob


3 Replies

SB Swetha Babu Syncfusion Team November 18, 2022 12:28 PM UTC

Hi Bob,


Greetings from Syncfusion.


We can get the base64 string using the DataUrl argument in OnExportComplete event of the chart. When calling the ExportAsync method, the OnExportComplete event gets triggered. We have created a simple blazor application to demonstrate the same and it can be downloaded from the below link.


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ChartExport-1707732033


Code Snippet:


<SfButton @onclick="ExportChart" Content="Export" CssClass="e-flat" IsPrimary="true"></SfButton>

<SfChart @ref="@chartInstance">   

    <ChartEvents OnExportComplete="@GetUrl"></ChartEvents>

</SfChart>

 

public async Task ExportChart(MouseEventArgs args)

    {

        await chartInstance.ExportAsync(ExportType.PNG, "Chart", Syncfusion.PdfExport.PdfPageOrientation.Portrait, false);

    }

    public void GetUrl(ExportEventArgs Args)

    {

        var dataURL = Args.DataUrl;

        string encodedString = dataURL.Split("base64,")[1];

        byte[] data = Convert.FromBase64String(encodedString);

    }


Kindly, revert us if you have any concerns.


Regards,

Swetha



TH Tim Hartog November 18, 2022 01:22 PM UTC

Hi Swetha,

Thank you very much for the fast response and solution.
This is exactly what I was hoping for.
I will build this solution in our program.


Regards,


Bob



DG Durga Gopalakrishnan Syncfusion Team November 22, 2022 05:53 AM UTC

Hi Bob,


Most welcome. Please get back to us if you need any further assistance. We are always happy in assisting you.


Regards,

Durga Gopalakrishnan.


Loader.
Live Chat Icon For mobile
Up arrow icon