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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to draw pie chart to pdf?

Thread ID:

Created:

Updated:

Platform:

Replies:

149645 Dec 4,2019 10:55 AM UTC Dec 5,2019 12:41 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: PDF
Fathimath Nazma Rasheed
Asked On December 4, 2019 10:55 AM UTC

I would like to draw the pie chart directly in the pdf. 
i have followed this link. https://help.syncfusion.com/file-formats/pdf/getting-started#creating-a-pdf-document-with-simple-text. and created the pdf but i would like to add a pie chart to the pdf.

Sowmiya Loganathan [Syncfusion]
Replied On December 5, 2019 12:41 PM UTC

Hi Fathimath, 

Thank you for contacting Syncfusion support.  

At present we do not have support to draw chart directly in PDF. However we can draw the chart as images in PDF document. Please refer the below code snippet for more details, 

//Create PDF document  
PdfDocument doc = new PdfDocument(); 
 
//Add a page to the document 
PdfPage page = doc.Pages.Add(); 
 
//Create PDF graphics for the page 
PdfGraphics graphics = page.Graphics; 
 
//Load the image from the disk 
FileStream imageStream = new FileStream("pie_chart.png", FileMode.Open, FileAccess.Read); 
PdfBitmap image = new PdfBitmap(imageStream); 
 
//Draw the image 
graphics.DrawImage(image, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); 
 
//Saving the PDF to the MemoryStream 
MemoryStream stream = new MemoryStream(); 
doc.Save(stream); 


Regarding Chart to PDF: 
We can export the pie chart to pdf using the export method in export module. Based on that we have prepared a sample for your reference. Please find the below sample and code snippet.   
  
Code Snippet:  

        <ejs-accumulationchart id="container" title="Mobile Browser Statistics" load="load"enableAnimation="false">  
            <e-accumulationchart-center x="50%" y="50%"></e-accumulationchart-center>  
            <e-accumulationchart-tooltipsettings enable="true"></e-accumulationchart-tooltipsettings>  
            <e-accumulationchart-legendsettings visible="false">  
            </e-accumulationchart-legendsettings>  
            <e-accumulation-series-collection>  
                <e-accumulation-series dataSource="ViewBag.dataSource" xName="xValue"yName="yValue" name="Browser" explodeIndex="0" explode="true"explodeOffset="10%">  
                    <e-accumulationseries-datalabel name="text" visible="true">  
                        <e-font fontWeight="600" color="white"></e-font>  
                    </e-accumulationseries-datalabel>  
                </e-accumulation-series>  
            </e-accumulation-series-collection>  
        </ejs-accumulationchart>  
<div>  
    <ejs-button id="button" content="Export" iconCss="e-icons e-play-icon" cssClass="e-flat" isPrimary="true"></ejs-button>  
</div>  
<script>  
    document.getElementById('button').onclick = () => {  
        var chart = document.getElementById('container').ej2_instances[0];  
        chart.exportModule.export('PDF''chart''Landscape', [chart] null, 1600);  
    };  
</script>  


Please let us know if you need any further assistance on this.  

Regards, 
Sowmiya Loganathan 



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon