I need to generate a report with a chart. I use UltraChart and the RenderPdfFriendlyGraphics method to get the image. RenderPdfFriendlyGraphics takes more than 6 minutes to execute because I have a lot of data. In order to make my application responsive I decided to generate the report in a separate thread, different from the UI thread. However, this didn't solve the problem. When RenderPdfFriendlyGraphics is executed, the UI freezes.1. Does RenderPdfFriendlyGraphics access the UI thread (make it active)?2. Could you suggest how to avoid the UI thread freezing (for example, so that the time elapsed since the start of the report generation could be updated in a form label)?
Hello Alexander,
Thank you for contacting Infragistics Developer Support!
I have been looking into your question and while I am not familiar with the amount and type of data that your chart is displaying, I have tested the UltraChart on my side with a large amount of data records and it does appear to handle numbers in the scope of ten thousands of records not as smoothly. Regarding techniques to execute the report generation asynchronously, I am afraid the RenderPdfFriendlyGraphics would be a black box here, and any additional handling should happen on application level. Furthermore, I would be curious if you aren’t observing any performance downgrades apart from the PDF exporting process, since displaying such an excessive amount of records may potentially impact the Ultra Chart initial rendering time as well?
Taking a step back, as an alternative solution I would suggest to consider leveraging the UltraDataChart instead. It is the more modern and supported charting component in the Ultimate UI for Windows Forms suite as opposed to the UltraChart who is practically retired.
The UltraDataChart can be saved as an image, which I have tested and seems to be working pretty fast for large datasets making up the visualization. Actually, if the chart being exported as PDF format is a must-have requirement for you, a Report that includes it can always be generated through the Document Engine once the image has been exported.
For your convenience, I am attaching such a sample app demonstrating this alternative. Please, note the chart visualization does not represent anything meaningful and is only rendered with as many data items for the purposes of the example.
As you will notice, the chart is rendering and exporting in a PDF document quite quickly. In conclusion, please, check out the referenced resources and let me know if you need any further assistance on the matter.
Best regards,Bozhidara PachilovaSoftware Developer
7282.UDC_Stacked_Column_Series.zip
The program I sent you doesn't contain data. I can't send it to you. Apart from the message that an error occurred, I have no more information. Therefore, I do not understand why the file is not sent. These are two .txt files, 3.2MB each. Now I'm looking for a way to do this.
I was unable to upload the data files here. So I used the link you provided.I uploaded the archive with the program and data. Please unzip the archive. Build the application. And run the program. Everything should work.
Hi Alexander,
Thank you for sharing the working sample!
I am able to run it now. I have followed the described steps to generate data and image.
It is possible that I am missing something about your scenario here, however, could you please, clarify what is supposed to happen at the end? You described the scenario involved generating a PDF report with the chart, however, in the provided code, I was not able to identify a Report generation implementation. Note, I have not really delved into the application code that much, and I am merely trying to clarify the expected result.
What I can suggest is to still adopt the approach exposed by the Infragistics Document Engine to publishing a report, which I believe works smoothly with the UltraChart and its RenderPdfFriendlyGraphics method. Please, check out this documentation page. I modified parts of the code in the MainForm.GetImage() method as below:
Report r = new Report(); Graphics g = r.AddSection().AddCanvas().CreateGraphics(); uc.RenderPdfFriendlyGraphics(g, width, height); r.Publish("..\\..\\Report.pdf", FileFormat.PDF); System.Diagnostics.Process.Start(("..\\..\\Report.pdf"));
And on my side, this appears to generate the report instantly. In addition, the quality seems quite satisfactory, on zoom as well.
The modified project can be found here.
Please, let me know if this accurately demonstrates what you’re trying to achieve and do elaborate further, in case I did not quite get the picture right. Thank you for your cooperation.
Also, I noticed that in the provided project, an outdated version of Ultimate UI for WinForms is referenced (16.2). This version is long out of support. I am testing against one of the supported versions (23.1). Please, note that if the behavior is only reproduced in an outdated version, the suggestion would be to upgrade to a supported one to leverage all introduced features and fixes since then. Additionall information can be found in our Product Lifecycle page.
Best regards, Bozhidara Pachilova
Description of the main problem:Our report uses a chart image with the received data. To do this, we load the data into UltraChart. Then we use the RenderPdfFriendlyGraphics method to get the image (the image must be of good enough quality).With a large amount of data (for example, 500k points), the RenderPdfFriendlyGraphics method takes a very long time to execute. In order for the user not to perceive this as a program freeze, we execute it in a background thread. In the main thread, we display a progress form with a timer so that the user can see the elapsed time.The main problem is that the RenderPdfFriendlyGraphics method returns control to the UI thread and it stops responding. The time stops updating, which looks like the program is frozen.My question is, is it possible to get a chart image in good quality and at the same time have a responsive UI so that the elapsed time on the progress form can be updated? This is necessary so that the user understands that the program continues to run and hasn't frozen.All this is demonstrated by my example that I sent you. Pay attention to the text message on the progress form.
I am wondering if you’ve had the chance to check out the gif and linked sample in my latest message below? I see that there is some confusion here in the order of the messages and replies, so I have marked that reply as “Suggested answer” for better clarity.
I believe the suggested approach there works as expected. The gif clearly shows that the time gets upated during the 5 seconds delay, which as far as I remember was also explicitly introduced, and with the given amount of data points as in the provided by you test app. Nothing else apart from the given code snippet was changed. Additionlly, the gif shows the received image quality in the result PDF.
Please, do confirm if you had checked out that last reply and all aspects around it, so that we can be sure that we have exhausted all options.
Best regards,
Bozhidara Pachilova
Hello, Bozhidara
First of all, I want to say thank you for your help. Your suggestions aren't exactly what we need, but they gave me an idea. It seems I found the main problem. Using the Graphics.ScaleTransform method increases the time it takes to get an image using the RenderPdfFriendlyGraphics method. If don't use ScaleTransform before calling RenderPdfFriendlyGraphics, everything works quickly and UI doesn't freeze.I'll try to find a solution without using ScaleTransform.
Alexander Osipenko