Jump to content
Software FX Community

Exporting Chart as Image


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.



Link to comment
Share on other sites

 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);

Link to comment
Share on other sites

  • 3 weeks later...

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




Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...