Is there a way to get the export easier?

Hello Syncfusion,


A while ago I reacted to another thread on the forum.

https://www.syncfusion.com/forums/169967/export-chart-data-to-base64

In there you used this sample:

<SfChart @ref="@chartInstance">
<ChartEvents OnExportComplete="@GetUrl">ChartEvents>
SfChart>
@code
{
private SfChart chartInstance;
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;
}
}

That works fine and all. But I created a chart as component. (Another razor page)
So when I press on the main page the button to create a PDF report. I access the chartInstance.ExportAsync.

private async void CreateReport()

{

string base64 = ColumnChart.CreateExportImage();

string base64 = PieChart.CreateExportImage();

}

This calls within the ColumnChart Razor file the method that does basicly chartInstance.ExportAsync();

But the problem that I have it that the "GetUrl" is not kicked till the the CreateReport is done.

public void GetUrl(ExportEventArgs Args)
{
var dataURL = Args.DataUrl;
}

Is there a way to have the dataurl returned whin the same function. Something like:

public async Task CreateExportImage()

{

base64 = null;

await ExportAsync(null);

while( GetUrl() == null) //As long the dataurl is still null wait till it's created

{

System.Threading.Thread.Sleep(500);

}

base64 = GetUrl();

return base64;

}

public async Task ExportAsync(MouseEventArgs args)

{

ColumnChart.ExportAsync(ExportType.PNG, "Chart", null, false);

}


(Example might be needed some more files to work)



Attachment: PDFExportChartSample_ed8d3a9.zip


2 Replies

SB Sridevi Bharathi Manohar Syncfusion Team April 15, 2022 04:02 PM UTC

Hi Bossink,


We are analyzing with your required scenario. We will update the status within two business days(19th April, 2022). We appreciate your patience until then.


Regards,

Sridevi Bharathi.



DG Durga Gopalakrishnan Syncfusion Team April 18, 2022 03:57 PM UTC

Hi Bossink,


Greetings from Syncfusion.


As per your attached snippet the GetUrl is the normal method which cannot return the base64 string. Then while clicking the CreateReport button,  the CreateExportImage method execution is completed before triggering GetChartImage method which returns the base64 string.


By default, OnExportComplete event will be triggered only when chart is exported and you can get the DataUrl value from that event. Please let us know if you have any concerns.


Regards,

Durga Gopalakrishnan.


Loader.
Up arrow icon