brownhead Posted January 30, 2009 Report Share Posted January 30, 2009 My program needs to be able to export the reports it creates into PDF files. I can make the PDF file just fine, but in order to add the Chart I need to save the Chart as an image, preferably PNG. Now comes the trouble spot, the chart needs to be resized inside the export function in order for it to fit smoothly on the page. How can I do this without displaying the chart to the user? I'm having difficulty explaining this so perhaps an example will help public void ToPFD(string FileName, Chart zChart){ // PDF functions up above// Set the width and height of the chartzChart.Width = zChart.Height = Math.Min(pdfPage.Width - 30, pdfPage.Height - tblEnd - 60); /* I have tried calling Refresh(), all the Invalidate*() functions, * and anything else that seemed likely to work here. None of them * did. I believe because there Asynchronous.. I was trying to * put to sleep this thread and then interrupt it when the refresh * was done but I couldn't figure out what event was called when * the refresh was finished. */ // Export the chartzChart.Export(tmpFile); } Thanks for taking a look. Hope to resolve this problem soon as I see no work around. Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 1, 2009 Author Report Share Posted February 1, 2009 Perhaps I should clarify this. My question is how do I make the chart do a complete redraw (including adjusting to its new dimensions) synchronously. A function call that doesn't return until the operation is finished is more or less what I'm looking for. I desperatley need a solution for this and I haven't been able to find one. Quote Link to comment Share on other sites More sharing options...
JuanC Posted February 2, 2009 Report Share Posted February 2, 2009 Unfortunately WPF does most of its job in a "render thread" so I am not sure if you can force a complete redraw asynchronously, even if you did do you want the chart to grow/shrink when generating the PDF? Have you considered creating a separate chart only used for the export? We added some special code to support this scenario of exporting a chart that has never been visible. Regards, JuanC Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 2, 2009 Author Report Share Posted February 2, 2009 I saw a post of yours that mentioned you had figured that out. I sent you a message about it yesterday. How would I go about doing that? Because that would be an excellant workaround. Quote Link to comment Share on other sites More sharing options...
JuanC Posted February 4, 2009 Report Share Posted February 4, 2009 I do not think we got your email. You will have to create a chart object in code and customize it in a similar way as the one being displayed on the screen, including binding it to the same data source. Regards, JuanC Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 5, 2009 Author Report Share Posted February 5, 2009  I had actually send a Private Message directly to you using the forum.  And creating a chart object then exporting it is not working for me. This is the code I'm using. (zChart is a reference to the original chart)  ChartFX.WPF.Chart newChart = new ChartFX.WPF.Chart();  newChart.Width = newChart.Width = Math.Min(page.Width - 30, page.Height - tblEnd - 60);  newChart.Style = ChartFX.WPF.Motifs.Basic.Style;  newChart.ItemsSource = zChart.ItemsSource;   // Export the chart to a png file  newChart.Export(ChartFX.WPF.FileFormat.Png, tmpPath); Quote Link to comment Share on other sites More sharing options...
JuanC Posted February 6, 2009 Report Share Posted February 6, 2009 I never got your private message. Can you expand on what is "not working" when using that code? Do you get an empty image? Can you post the image you get? Are you executing this code on the UI thread or are you creating a background thread? Regards, JuanC Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 6, 2009 Author Report Share Posted February 6, 2009 By not working I mean a blank chart is exported. I have attached the exported image. The thread that the function is executing on is the main UI thread. Â Hope to hear back from you soon. Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 24, 2009 Author Report Share Posted February 24, 2009 Â I've been able to ignore this problem and continue working, but its still a problem that needs to be fixed before release. Is there a known solution as of yet? Quote Link to comment Share on other sites More sharing options...
JuanC Posted February 24, 2009 Report Share Posted February 24, 2009 We have been unable to reproduce this problem, in our tests using the sample code you posted results in a valid png, this is the code we tested. ChartFX.WPF.Chart newChart = new ChartFX.WPF.Chart();newChart.Width = 500;newChart.Height = 300;newChart.Style = ChartFX.WPF.Motifs.Basic.Style;newChart.ItemsSource = zChart.ItemsSource; // Export the chart to a png filenewChart.Export(ChartFX.WPF.FileFormat.Png, "C:\\Temp\\Test.png"); Are you using any special settings in the XAML or Code for zChart? Have you tried to duplicate this issue in a sample app with a XAML Window with a simple chart (you might use an XmlDataProvider with dummy chart so that you can send us a complete sample). To help us try to reproduce the problem please post the following information: OS including Service Pack.NET Version including Service PackFile Version for ChartFX.WPF.dllVideo Card Manufacturer and Driver Version Regards, JuanC ChartFXWPFTest12.zip Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 24, 2009 Author Report Share Posted February 24, 2009 My system spec: OS Name: Microsoft Quote Link to comment Share on other sites More sharing options...
JuanC Posted February 25, 2009 Report Share Posted February 25, 2009 Can you double check the file version for ChartFX.WPF.dll? It should be 8.0.NNNN.NNNN. 2.0.50727 sounds like the version of the .NET framework 2.0 JuanC Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 25, 2009 Author Report Share Posted February 25, 2009 Ah, my mistake. Chart FX Version: 8.0.3155.18127 Quote Link to comment Share on other sites More sharing options...
JuanC Posted February 25, 2009 Report Share Posted February 25, 2009 I would recommend you download and install our RC1 bits. JuanC Quote Link to comment Share on other sites More sharing options...
brownhead Posted February 26, 2009 Author Report Share Posted February 26, 2009 It works now, thank you very much for all of your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.