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.
Unfortunately, activation email could not send to your email. Please try again.

Render Chart in code and draw to PDF

Thread ID:

Created:

Updated:

Platform:

Replies:

126977 Oct 19,2016 08:09 AM Oct 26,2016 12:34 PM WPF 7
loading
Tags: Chart
Victor Dienstbier
Asked On October 19, 2016 08:09 AM

Hi!

Since some time now I'm trying to create a SfChart in code behind (without showing it in UI) and draw this chart on an newly created PDF File. I've had a lot of help from the forum but I wasn't able to find any clue to solve my problem. It's meant to be for a protocol.


The PDF is created and there is some kind of blank square where the chart should be and the size seems to be correct.

Please help me to solve the problem!

Thank you very much!



The example code looks like this:

public static void ProtokollErstellen(Pumpenmessdaten.MessungenSammlung MessdatenSammlung)

{

PdfDocument document = new PdfDocument();

document.PageSettings.Size = PdfPageSize.A4;

document.PageSettings.Margins.All = 10;


PdfPage page = document.Pages.Add();

PdfGraphics graphics = page.Graphics;


SfChart chart = new SfChart()

{

Header = "Kennlinie"

};

NumericalAxis primaryAxis = new NumericalAxis()

{

Header = "Volumenstrom [l/s]",

ShowTrackBallInfo = true

};

chart.PrimaryAxis = primaryAxis;

//Adding vertical axis to the chart

NumericalAxis Axis1 = new NumericalAxis()

{

Header = "Förderhöhe [m]",

ShowTrackBallInfo = true

};

chart.SecondaryAxis = Axis1;


PdfBitmap bmpChart = new PdfBitmap(RenderChartToImage(chart));

page.Graphics.DrawImage(bmpChart, 0, 150);


document.Save(sDateiname);

System.Diagnostics.Process.Start(sDateiname);

}


private static Image RenderChartToImage(SfChart chart)

{



chart.RenderSize = new System.Windows.Size(500, 500);


RenderTargetBitmap renderBitmap =


new RenderTargetBitmap(


(int)chart.RenderSize.Width,


(int)chart.RenderSize.Width,




96,


96,



PixelFormats.Pbgra32);




renderBitmap.Render(chart);



using (MemoryStream outStream = new MemoryStream())






{


//Chart is saved in memorystream


chart.Save(outStream, new PngBitmapEncoder());


Image image = Image.FromStream(outStream);


return image;




}


}






Devi Aruna Maharasi Murugan [Syncfusion]
Replied On October 20, 2016 07:09 AM

Hi Victor, 
  
Thanks for contacting Syncfusion Support, 
  
We are able to achieve your requirement (without showing the chart in UI) by measuring the chart size. We have prepared a demo sample based on your requirement and it can be downloaded from below link, 
  
Sample: ChartToPDF(2) 
  
Regards, 
Devi 





Victor Dienstbier
Replied On October 20, 2016 09:24 AM

Hi Devi!

Thank you very much for your help! It works great...

I have some more questions  ;-)
Is it somehow possible to increase the quality of the chart? It kind of looks very low quality... Or is there even the possibility to make a chart on a PDF which is interactive?

Thank you very much!

Victor

Devi Aruna Maharasi Murugan [Syncfusion]
Replied On October 21, 2016 08:52 AM

Hi Victor, 
  
Thanks for your update. 
  
By default, we are rendering the HighQuality image with the RenderTargetBitmap’s RenderOption. However, we are able to achieve your requirement (high quality image) by increasing the chart size (same size set to exported image). We have modified the sample based on your requirement and it can be downloaded from below link, 
  
Sample: ImageModified 
  
Regards, 
Devi 





Victor Dienstbier
Replied On October 24, 2016 04:13 AM

Hi Devi!

Thanks again for your help!

Unfortunately it doesn't seem to improve the quality of the image for me! I've tried everything... I don't know either why I can't use BmpBitmapEncoder(). For me only the PngBitmapEncoder() works without showing an error :-(

I added an example protocoll to show you what I mean...

Is there anything else I can do? The most awesome thing would of course be some kind of plugin for Charts in the PDF to use it like in an App. To have the ability to zoom etc. Is this even possible?

Thank you very much for your help!

Victor

Attachment: 20161024_100511_Protokoll_a0a35153.zip

Devi Aruna Maharasi Murugan [Syncfusion]
Replied On October 25, 2016 09:21 AM

Hi Victor, 
  
Thanks for your update. 
  
Query 1: why I can't use BmpBitmapEncoder() 
  
As we are unable to reproduce the reported problem at our end, please provide more information regarding the error occurred, like screenshot and the information regarding your machine 
  
Query 2: some kind of plugin for Charts in the PDF to use it like in an App. 
  
We don’t have support to use chart in pdf as plugin. 
  
Regards, 
Devi 


Victor Dienstbier
Replied On October 25, 2016 09:48 AM

Hi Devi!

Thanks again for your help!

I'm working on Windows 7 and using Visual Studio 2015 with these:
Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055
Installierte Version: Professional
LightSwitch for Visual Studio 2015   00325-60000-56475-AA421
Microsoft LightSwitch for Visual Studio 2015
Visual Basic 2015   00325-60000-56475-AA421
Microsoft Visual Basic 2015
Visual C# 2015   00325-60000-56475-AA421
Microsoft Visual C# 2015
Visual C++ 2015   00325-60000-56475-AA421
Microsoft Visual C++ 2015
Visual F# 2015   00325-60000-56475-AA421
Microsoft Visual F# 2015
Allgemeine Azure-Tools   1.8
Bietet allgemeine Dienste für die Verwendung durch Azure Mobile Services und Microsoft Azure-Tools.
Application Insights-Tools für Visual Studio-Paket   7.10.01020.1
Application Insights-Tools für Visual Studio
ASP.NET and Web Tools 2015.1   14.1.20512.0
ASP.NET and Web Tools 2015.1
ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563
ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
For additional information, visit http://www.asp.net/
Azure App Service Tools v2.8.1   14.0.11123.0
Azure App Service Tools v2.8.1
Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.
Azure Data Lake Tools for Visual Studio   2.0.6000.0
Microsoft Azure Data Lake Tools for Visual Studio
JavaScript-Sprachdienst   2.0
JavaScript-Sprachdienst
JavaScript Project System   2.0
JavaScript Project System
Microsoft .NET Core Tools (Preview 1)   14.1.20512.0
Microsoft .NET Core Tools (Preview 1)
Microsoft Azure-Tools   2.9
Microsoft Azure-Tools für Microsoft Visual Studio 2015 – v2.9.40518.2
Microsoft Azure HDInsight HQL Service   2.0.6000.0
Language service for Hive query
Microsoft Azure HDInsight Tools for Visual Studio   2.0.6000.0
An integrated development environment for HDInsight application development.
Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools
NuGet-Paket-Manager   3.4.4
NuGet-Paket-Manager in Visual Studio. Weitere Informationen zu NuGet finden Sie unter "http://docs.nuget.org/".
Office Developer Tools for Visual Studio 2015 ENU   14.0.23928
Microsoft Office Developer Tools for Visual Studio 2015 ENU
PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio-Erweiterung zur Visualisierung aggregierter Zusammenfassungen vom PreEmptive Analytics-Produkt.
Python Tools for Visual Studio   2.2.40623.00
Python Tools for Visual Studio provides IntelliSense, projects, templates, Interactive windows, and other support for Python developers.
Python Tools for Visual Studio - Django Integration   2.2.40623.00
Provides templates and integration for the Django web framework.
Python Tools for Visual Studio - Profiling Support   2.2.40623.00
Profiling support for Python projects.
SQL Server Data Tools   14.0.60519.0
Microsoft SQL Server Data Tools
Syncfusion ASP.NET MVC (Mobile) Extension   14.3.0.49
Provides Project Templates to create Syncfusion ASP.NET MVC (Mobile) projects.
Syncfusion ASP.NET MVC (Web) Extension   14.3.0.49
Provides Project Templates to create Syncfusion ASP.NET MVC (Web) projects and samples.
Syncfusion Item Templates    14.3.0.49
Adds new Syncfusion items to projects with necessary base code.
Syncfusion Reference Manager   14.3.0.49
A useful add-in for adding and migrating Syncfusion Assembly References for Windows Forms, WPF, and Silverlight projects.
Syncfusion.VSExtension.Troubleshooter   14.1.0.41
Add-in for Troubleshooting the Syncfusion projects.
ToolWindowHostedEditor   1.0
Hosting json editor into a tool window
TypeScript   1.8.36.0
TypeScript-Tools für Visual Studio
Visual Studio Tools for Universal Windows Apps   14.0.25527.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.
Workflow Manager Tools 1.0   1.0
Dieses Paket enthält die erforderlichen Visual Studio-Integrationskomponenten für Workflow Manager.

and I'm using Syncfusion 14.3.0.49 :-)

Do you need any more information?

I also made some screenshots of the error. Are they helping?

Maybe you can consider to add such a feature (PDF addIns) in the future! I think alot of people would be amazed to have something like that :-)

Have a great day and I hope the information are enough and you can help me with these :-)


Victor

Attachment: Screenshots_ebb73089.zip

Sheik Syed Abthaheer M [Syncfusion]
Replied On October 26, 2016 12:34 PM

Hi Victor,

Thanks for your update.

When we look at the updated error screenshots, it seems system related issue. Since BmpBitmapEncoder issue occurred in System.Drawing assemblies.
For PDF plugin, we will analyze the feasibility to include this support.

Regards,
M. Sheik


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.

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.

;