Knowledgebase
Rendering chart to bitmap in memory
Posted by Admin - on 12 February 2019 04:52 PM
|
|
For a documentation article on this topic, please see Screenshots, Printing and Export to XPS. 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. Creating a ChartFirst, create a SciChartSurface which you want to save to bitmap: 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<IRenderableSeries>() { 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"); Rendering the Chart in MemoryThen you can render the chart in memory. To do this you can call the ExportToBitmapSource() method to render the 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(); The exported chart should look like the one below: Further ReadingTo learn more about the Chart Exporting feature in SciChart please see our documentation: | |
|