- Home
- Forum
- ASP.NET Core - EJ 2
- How to draw pie chart to pdf?
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.
SIGN IN To post a reply.
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); |
UG documentation link: https://help.syncfusion.com/file-formats/pdf/working-with-images?cs-save-lang=1&cs-lang=asp.net%20core#inserting-an-image-in-a-new-document
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> |
UG documentation link : https://help.syncfusion.com/aspnet-core/chart/getting-started
Please let us know if you need any further assistance on this.
Regards,
Sowmiya Loganathan
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
FN Fathimath Nazma Rasheed
- Dec 4, 2019 10:55 AM UTC
- Dec 5, 2019 12:41 PM UTC