Knowledgebase: Export to Bitmap
Rendering chart to bitmap in memory
Posted by Admin - on 21 March 2014 11:20 AM

To render chart in memory (without showing on screen), you can use the following technique. This technique can be used to render-to-bitmap on a server environment, or for creating reports.

First, create chart which you want to save to bitmap:

var series = new FastLineRenderableSeries()
{
    SeriesColor = 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");

Then you should render chart in memory. To do this you can use following method and use it to render chart in memory:

// 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 = 1000;
surface.Height = 1000;

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

Results of rendering to bitmap

(1 vote(s))
Helpful
Not helpful

CONTACT US

Not sure where to start? Contact us, we are happy to help!


CONTACT US

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL. Email: Legal Company Number: 07430048, VAT Number: 101957725