WPF Charting Documentation - SciChart WPF Charts SDK v5.x
Screenshots, Printing and Export to XPS

SciChart features a number of ways to export the chart to bitmap, print or vector format.

Export to BitmapSource

SciChart supports export to BitmapSource. To screenshot the current chart on screen and get a bitmap in memory, call the following code:

Export to BitmapSource
Copy Code
// Assumes the SciChartSurface is on screen and currently visible
// What you see is what will be exported
BitmapSource bitmap = sciChartSurface.ExportToBitmapSource();

Export to Png/Jpeg/Bmp File

SciChart supports exporting to file, with PNG, JPEG or BMP formats. To save the current chart visual to file, call the following code:

Export to Png/Jpeg/Bmp File
Copy Code
// Assumes the SciChartSurface is on screen and currently visible
// What you see is what will be exported to file
sciChartSurface.ExportToFile(string filename, ExportType.Png);

Copying the Chart to Clipboard

To copy the current chart visual to clipboard, first you need to export to BitmapSource, then set the image on the Clipboard. For instance:

Copying the Chart to Clipboard
Copy Code
private void CopyToClipboard()
{
   // SciChartSurface natively exports to in-memory bitmap-source
   var bmp = customUserControl.SciChartSurface.ExportToBitmapSource();
   Clipboard.SetImage(bmp);
}

Printing to PDF / Printer / XPS

SciChart supports printing (shows a Print Dialog). The following code prints the current chart visual to a printer specified by the user. You can print to PDF or XPS by choosing a PDF writer or Microsoft XPS writer as the current printer.

Printing to PDF / Printer / XPS
Copy Code
// Assumes the SciChartSurface is on screen and currently visible
// What you see is what will be printed
// This method will show a print dialog
sciChartSurface.Print(string description = null);

Exporting a Bitmap at Specific Resolution

This one is difficult. When you have a SciChartSurface on screen, it’s size is constrained by the parent and the WPF Layout system, so you can only export the current visual on screen. If you want to export at any other resolution, then you have to build a chart in memory (without showing it) and give it a size (Width, Height) then export it.

For instance, the following code will export a SciChartSurface at resolution 1900x1200:

Exporting a Bitmap at Specific Resolution
Copy Code
var series = new FastLineRenderableSeries()
{
    Stroke = Colors.Red,
    DataSeries = GetDataSeries()
};

var xAxes = new AxisCollection()
{
    new NumericAxis()
};

var yAxes = new AxisCollection()
{
    new NumericAxis()
};

var surface = new SciChartSurface()
{
    ChartTitle = "Rendered In Memory",
    XAxes = xAxes,
    YAxes = yAxes,
    RenderableSeries = new ObservableCollection() { series },
    Annotations = new AnnotationCollection()
    {
        new BoxAnnotation()
        {  
            X1 = 10,
            X2 = 30,
            Y1 = 10,
            Y2 = 40,
            Background = new SolidColorBrush(Colors.Green),
        },

        new VerticalLineAnnotation()
        {
            X1 = 35,
            Stroke = new SolidColorBrush(Colors.Yellow),
            StrokeThickness = 3,
            ShowLabel = true,
            LabelPlacement = LabelPlacement.Axis
        }
    }
};

ThemeManager.SetTheme(surface, "Chrome");

// When rendering in memory without showing, we must specify a size
// WPF has no idea what the size of the chart should be unless it
// is hosted in a Window
surface.Width = 1900;
surface.Height = 1200;

// Export to bitmap
var bitmapSource = surface.ExportToBitmapSource();

Which results in something like this:

Scalable Vector (XPS) Export

As of SciChart v4, we now support scalable vector export via the XamlRenderSurface.

The XamlRenderSurface is described in Section 4.15.4, and is a render surface plugin which draws everything on the SciChartSurface to a WPF Canvas. This enables SciChart to export directly to vector format, and the output (being a vector) is scalable, enabling high resolution printing and reporting with SciChart.

To enable the XamlRenderSurface and export a high quality vector, use the following code:

Scalable Vector (XPS) Export
Copy Code
// Requires using SciChart.Drawing.XamlRasterizer for the ExportToXps extension method
//

// Assuming you have a SciChartSurface instance
var sciChartSurface = new SciChartSurface();

// Swap RenderSurface to XamlRenderSurface
var oldRenderSurface = sciChartSurface.RenderSurface;
sciChartSurface.RenderSurface = new XamlRenderSurface();

// Optional size. Passing null means render at current size. Else passing
// a size attempts to render at the provided size
Size? size = null;

// Export to XPS file
sciChartSurface.ExportToXps("C:/Test.xps", size);

// Reset the RenderSurface
sciChartSurface.RenderSurface = oldRenderSurface;

NOTE: The XamlRenderSurface Renderer plugin is available in the SciChart WPF Enterprise and SciChart WPF SDK Enterprise products only. 

 

 

 


SCICHART ® is a Registered Trademark in the UK, US and EEC. Copyright SciChart Ltd 2011-2018.

Email us to give feedback!