Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
130
Programmatic reports with XamWebChart?
posted

I am using the 2011 Reporting CTP to try anb write code that will take a XamWebChart instance, stick it in a report, then print it.  This is all in SL4 and, ideally, no XAML would be involved.  I cannot seem to find any useful documentation or samples regarding the relevant classes (Report, Section).

This was a trivial task with Telerik's libraries, but I have not been able to determine how this can be accomplished using Infragistics' libraries.

Parents Reply
  • 2848
    posted in reply to William

    The Infragistics.Documents library ships with Windows Forms and it's documented here

    http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/html/Win_Infragistics_Document_Engine.html

    The SL version is a port of that one, so it could be slightly different, and as I said, it could not be included in future versions of NA Reporting.

    That said, we are using it for exporting XAML controls to PDF with Reporting, so it's possible to do. You cannot use it for printing tough.

    To get an image included in the report you need to do something like this:

    var sfd = new SaveFileDialog();

    bool? result = sfd.ShowDialog();
     
    if (result.Value)
    {
        BitmapSource bitmap = ...; // This object should hold the chart's bitmap
     
        using (var stream = sfd.OpenFile())
        {
            var report = new Report();
            var section = report.AddSection();
            var encodedBitmap = new MemoryStream(); 
            // for JPEG encoding
            new JpegImageEncoder().Encode(bitmap, new List<EncodingProperty> { new JpegQualityProperty { Quality = 100 } }, encodedBitmap);
            var image = System.Drawing.Image.FromStream(encodedBitmap); 
            section.AddImage(new Image(image)); 
            report.Publish(stream, FileFormat.PDF);
        }
    }
    To create a bitmap from the chart, you can do something like:

    bitmap = new WriteableBitmap(chart, null);

    Where chart is the instance of xamWebChart, and it should be somewhere in the Visual Tree. If you don't want to show it, you could try putting it into a ViewBox with Opacity = 0. 
    As I mentioned, our current thinking is not to ship this library as a product that we support, so it could happen that you don't see it in future versions of the tool. 
    Regards,
    Andres

Children