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

Export Chart to Excel and PDF

I have a need to export a chart to PDF and Excel, how do I do this?  I have found the syncfusion.EJ.Export assemblies, and I am able to export grids, but the excelexport.export function for charts needs a datasource, and I can't figure out how to properly format this datasource.  It's obviously not the datasource returned by the REST service that we retrieved to generate the chart.

3 Replies

SK Sanjith Kesavan Syncfusion Team September 14, 2015 12:48 PM UTC

Hi David Elies,
Thanks for using Syncfusion product. We have analyzed your query. Currently we are not having support for exporting the chart to PDF. But we can achieve this through work around.
Find the below steps for exporting chart in PDF.
1. For export the chart to pdf first we have to save the image of the chart.


Save the image of the chart with the name Chart. The location is needed for PDF generator. Save the image in below location
Location: F:\Incident\Samples\WebApplication1-253868983\WebApplication1\WebApplication1\exportchartImage\Chart.png

For export the chart in the PDF we need to add Syncfusion.Pdf.Base.dll in the project. Once the above steps are completed click the PDF button to export the chart in the PDF. We have used AJAX post in the button click to call DATACURD method in home controller.



In the home controller add the following namespace.



We have added the below code in the DATACURD method in the home controller as like below.



Now the chart will be exported in the PDF. Please find the below screenshot.




Note: Export the chart to excel will only support from the essential studio version 13.2.0.29

For export the chart to excel please refer the following dll’s.

1. Syncfusion.EJ.Export.dll

2 .Syncfusion.XlsIO.Base.dll

To achieve the export to excel please add the following code in the view page of the sample

[JS]


In the above code we have called the ExportToExcel method in the home controller. ExportToExcel method contains code to export the chart in excel. Please find the below code example

Code Example:






To export the chart to excel please click the export to excel image. Please find the below screenshot


Now the chart will be exported into excel



The chart is exported in excel like below.



We have prepared the sample as per your requirement. Please find the sample from below mentioned location.

Sample Link: http://www.syncfusion.com/downloads/support/forum/120227/ze/WebApplication1-1844291803

Please let us know if you have any concern.


Regards,

Sanjith K.



DE David Elies September 14, 2015 04:30 PM UTC

Thanks for your reply.  For the PDF export, is it possible to work with the data url, or a filestream or some other way of creating the PDF without actually saving the file?


SK Sanjith Kesavan Syncfusion Team September 15, 2015 10:45 AM UTC

Hi David Elies,
Thanks for your reply. We have analyzed your query and we have prepared the sample as per your requirement. In the button click event we have called the ExportChart function
Please find the below code
[JS]


In the ExportChart() method we have written the below code.

In the above code we have get element of the chart and canvas using its unique id. For canvas we have set the width as 1000px and height as 800px. And then we have drawn this image inside that canvas. In the above code we have created the form using CreateElement function and posted that form to the DownloadContent method in the home controller. CreateElement method contains the following code

The DownloadContent method in home controller contains the following code.


This download content method created the pdf file with the name of the “Chart.pdf”. Please find the below screenshot.
Screenshot of the chart:

Screenshot while click the export button, chart is exported into pdf.


Exported chart in pdf

Please find the sample from below mentioned location.
Sample Link: http://www.syncfusion.com/downloads/support/forum/120227/ze/col-1758828875
Please let us know if you have any concern.

Regards,
Sanjith K.

Loader.
Live Chat Icon For mobile
Up arrow icon