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

How to draw pie chart to pdf?

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.

1 Reply

SL Sowmiya Loganathan Syncfusion Team 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 



Loader.
Live Chat Icon For mobile
Up arrow icon