SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
0
0

I’m trying to make sure I can get the full extents of the image before converting to something is useful for inclusion in a report; however, when I run the following code the image is not showing the entire zoomed out chart. The chart is however zoomed out when this function is complete.

Dispatcher.Invoke(() => CrosslineGraph.DoseChart.ZoomExtents());           
        BitmapSource bitmap = CrosslineGraph.DoseChart.ExportToBitmapSource();
        byte[] bytes;

        using (MemoryStream stream = new MemoryStream())
        {
            BitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bitmap));
            encoder.Save(stream);
            bytes = stream.ToArray();
        }
Version
5.2.1.11757
  • You must to post comments
Best Answer
1
0

Because you’re exporting you will need to set SciChartSurface.RenderPriority=Immediate when changing your properties so that the chart will draw immediately, before export.

I would suggest something like this

try
{
    sciChartSurface.RenderPriority = RenderPriority.Immediate;
    sciChartSurface.ZoomExtents();
    var bitmap = sciChartSurface.ExportToBitmapSource();
}
finally
{
    sciChartSurface.RenderPriority = RenderPriority.Normal;
}

Be advised, RenderPriority.Immediate means ‘redraw on anything changed, properties, styles, data’ and will make your application extremely slow if you forget to set it back to Normal.

  • Chris Kirkman
    I have more than one chart in my UI, and they are on separate tabs. As soon as I call .ExportToBitmapSource() for one of the charts that is not shown (it’s tab is not selected) an exception is thrown… UIElement.Measure(availableSize) cannot be called with NaN size. Is there a way around this?
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.