Hello,
I'm beggining with Infragistics tools and I'm building an app with some statistic charts. At this point, I'm trying to add a button that allows me to export my XamDataChart to an Excel File.
Thank you for any help or idea.
Are you working with Silverlight or WPF?
I'm working with WPF
Hi slaimi,
This should certainly be possible, I have included the following link to one of our blog posts, by Petar; which demonstrates converting the XamDataChart to a bitmap and then exporting the resulting image to Excel; there is also an accompanying sample application which produces this behavior for further context. The necessary approach for this behavior is described in both Silverlight and WPF versions of the chart.
Controls to images http://es.infragistics.com/community/blogs/petar_monov/archive/2012/03/14/controls-to-images.aspx
If you have any further questions that I may assist you with, please let me know.
Sincerely, Chris K Developer Support Engineer Infragistics, Inc. www.infragistics.com/support
Thanks a lot Chris, that really helped.
I've been also trying to export it to a PDF file, I almost did it but I still have a little problem as I'm having only a part of my XamDataChart in the PDF file and not the entire Chart.
I've been working on this on my own so maybe you can give me another way to do this.
Thanks again.
Hi slaimi,You are certainly welcome. It may be possible to export the chart to pdf, but this behavior is not supported yet with our WPF/Silverlight components. One possible approach that I can think of would include implementing the Documents engine from Windows Forms, (which does support exporting to pdf), wherein a report is created with a report section as its content; this component would then be hosted in WPF, an image of the chart area added to the report section and then exporting the resulting report to pdf; this approach may work in theory.What is the current approach that you are using? I would be more than happy to take a look at your current implementation and offer my suggestions.Sincerely,Chris KDeveloper Support EngineerInfragistics, Inc.www.infragistics.com/support
I am just checking if you require any further assistance on the matter.
Hello Slaimi,
I have been looking into latest post and it is occurs because the provided approach uses the actual size(height,width) of the XamDataChart. In this scenario the width of the PDF page is not big enough to show the whole chart. If you would like to export the entire chart to the pdf page you can check the actual width of the XamDataChart in the ‘SaveImage’ method like :
if (element != null)
{
RenderTargetBitmap bmpSource;
if (element.ActualHeight < 800)
bmpSource =
new RenderTargetBitmap(
(int)element.ActualWidth,
(int)element.ActualHeight, 96, 96,
PixelFormats.Pbgra32);
}
else
(int)element.ActualHeight, 60, 60,
bmpSource.Render(element);
imgEncoder.Frames.Add(BitmapFrame.Create(bmpSource));
using (Stream stream = File.Create(fileName))
imgEncoder.Save(stream);
stream.Close();
I am attaching a modified version of Chris’ sample application(ExportXDChartToPDF119194_Modified.zip).
Please note that this is a custom approach.
Let me know, if you need any further assistance on this matter.
Hi Chris,
I still have the same problem with this approach: when my chart is on full screen, the PDF file contains only a part of the chart and not the entire chart. You can try with your example and modify the width and the height.
I would like to thank you for your precious help.
Scincerely.
Hi Slaimi,I took a look at the blog post that you mentioned and the approach that Tom describes is exactly what I had in mind.I have included a modified version of that sample which demonstrates this behavior; to use the approach you would need to also install NetAdvantage for Windows Forms which includes the Documents assemblies that are required; for my sample, I have included only the assemblies necessary that you may not have on your machine.Please take a look at the attached sample and if you have any further questions regarding this behavior, please let me know.Sincerely,Chris KDeveloper Support EngineerInfragistics, Inc.www.infragistics.com/support
Hi,
Well here's what my code looks like
Report report = new Report(); EmbeddedVisualReportSection section1 = new EmbeddedVisualReportSection(this.Linechart); report.Sections.Add(section1);
// here I add the xamdatachart to a section (this.Linechart) and add the section to a Report object (I'm using Infragistics.Windows.Reporting)
string PDFPrinterName = "Bullzip PDF Printer"; string sLocalAppData = Solution.GetEnv("LOCALAPPDATA"); if (sLocalAppData == "") { sLocalAppData = Solution.GetEnv("USERPROFILE") + @"\Local Settings\Application Data"; } string PrinterSettingFileName = sLocalAppData + @"\PDF Writer\" + PDFPrinterName + @"\runonce.ini";
System.Text.Encoding iso8859 = System.Text.Encoding.GetEncoding("ISO-8859-1"); FileStream fs = new FileStream(PrinterSettingFileName, FileMode.Create, FileAccess.Write); StreamWriter sr = new StreamWriter(fs, iso8859);
string TempFilename = System.IO.Path.GetTempFileName(); string OutputFilename = TempFilename + ".pdf"; string StatusFilename = TempFilename + ".log"; sr.WriteLine("[PDF Printer]"); sr.WriteLine("Output = " + OutputFilename); sr.WriteLine("RememberLastFileName = no"); sr.WriteLine("RememberLastFolderName = no"); sr.WriteLine("ShowSaveAs = never"); sr.WriteLine("ConfirmOverwrite = no"); sr.WriteLine("ShowSettings = never"); sr.WriteLine("ShowPDF = no"); sr.WriteLine("ShowProgress = no"); sr.WriteLine("ShowProgressFinished = no"); sr.WriteLine("SuppressErrors = yes"); sr.WriteLine("Author = " + m_Solution.ReadResourceFromXaml(this, "msg_PDFAuthor")); sr.WriteLine("Format = pdfa1b"); sr.WriteLine("StatusFile = " + StatusFilename); sr.Close(); fs.Close(); report.ReportSettings.PrintQueue = new PrintQueue(new PrintServer(), PDFPrinterName); report.Print(false, false);
// as u can see, here I'm creating a filsestream to add all the informations and I'm using the BullZip PDF Printer to export the file
Process epg = new Process(); epg.StartInfo.UseShellExecute = true; epg.StartInfo.FileName = System.IO.Path.GetFileName(OutputFilename); epg.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(OutputFilename); epg.StartInfo.Arguments = ""; epg.StartInfo.Verb = "open"; epg.Start();
//last step is to lanch the process with the file created
the problem here is that I'm having only a part of the chart as shown in the images
and here's another approach that I have found but couldn't use http://es.infragistics.com/community/blogs/tom_puglisi/archive/2012/01/16/wpf-data-chart-to-pdf.aspx
please take the time to look at them and thanks for the help.
Sincerely