SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & 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!

0
0

Have a good day!

We are working with scichart render context to create 2d sprite. We have already optimized our code, but there is still problem.
When we put annotation, where we bind our image, outside the function, the image stops rendering. We’ve made that you had told us to do in previous post
( https://www.scichart.com/questions/question/memory-usage-part-2 ), but it doesn’t make a sense. We’ve found out that when we create
this annotation inside the function and when we pan the image it takes too many memory resources. It is caused by creating many annotations of this type
and therefore there is queue to the garbage collector. That’s why our goal is to put this annotation outside the function and just change image that is binded
to the annotation. Is there any way to solve it?

Code snippets:

Annotation outside the function (image shows, but doesn't render, it takes less memory)

        BackgroundImageAnnotation backgroundImage = null;

        private void OnRedrawWellSection(object sender, IRenderContext2D e)
        {
            e.Clear();
            e.SetPrimitvesCachingEnabled(false);
            double density;                        
            double density1;                        
            var minThltest = (double)SciChartSurface.XAxis.VisibleRange.Min;
            var maxThlTest = (double)SciChartSurface.XAxis.VisibleRange.Max;
            var minTvdTest = -2000;
            var maxTvdTest = -700;
            var xCalc = SciChartSurface.XAxis.GetCurrentCoordinateCalculator();
            var yCalc = SciChartSurface.YAxis.GetCurrentCoordinateCalculator();

            density = SciChartSurface.GridLinesPanel.Height/(double) SciChartSurface.YAxis.VisibleRange.Diff;

            density1 = SciChartSurface.GridLinesPanel.Width/(double)SciChartSurface.XAxis.VisibleRange.Diff;

            using (SciChartSurface.SuspendUpdates())
            {
                if (backgroundImage == null)
                {
                    backgroundImage = new BackgroundImageAnnotation
                    {
                        CoordinateMode = AnnotationCoordinateMode.Relative,
                        X1 = 0,
                        Y1 = 0,
                        AnnotationCanvas = AnnotationCanvas.BelowChart,
                    };
                }

                var mainWindow = Application.Current.MainWindow;
                var source = PresentationSource.FromVisual(mainWindow);
                if (source == null || source.CompositionTarget == null) return;

                var width = (int)SciChartSurface.ActualWidth;
                var height = (int)SciChartSurface.ActualHeight;
                if ((int)SciChartSurface.ActualWidth == 0)
                    width = 1;
                if ((int)SciChartSurface.ActualHeight == 0)
                    height = 1;
                WriteableBitmap writeableBmp = BitmapFactory.New(width, height);
                var color = Colors.Blue;
                for (double i = minTvdTest; i < maxTvdTest; i=i+density)
                {
                    var t1 = (int) xCalc.GetCoordinate(minThltest);
                    var t2 = (int) yCalc.GetCoordinate(i);
                    var t3 = (int) xCalc.GetCoordinate(maxThlTest);
                    var t4 = (int) yCalc.GetCoordinate(i);
                    if (i<-1500)
                    {
                        color = Colors.Green;
                    }
                    else
                    {
                        if (i<-1000)
                        {
                            color = Colors.Red;
                        }
                        else
                        {
                            color = Colors.Orange;
                        }
                    }
                    writeableBmp.DrawLineBresenham(t1, t2, t3, t4, color);
                }
                backgroundImage.ImageSource = writeableBmp;
                var sprite = e.CreateSprite(backgroundImage);
                e.DrawSprite(sprite, new Rect(0, 0, width, height), new Point(0, 0));
                e.Layers.Flush();
                writeableBmp = null;
                backgroundImage.ImageSource = null;
                e.DisposeResourceAfterDraw(sprite);
            }
        }

Annotation inside the function (image shows, renders, but when we pan, it takes many resources and it doesn’t invoke destructor at once)

// We put the declaration of annotation in the function scope
// BackgroundImageAnnotation backgroundImage = null;

private void OnRedrawWellSection(object sender, IRenderContext2D e)
{
    e.Clear();
    e.SetPrimitvesCachingEnabled(false);
    double density;                        
    double density1;                        
    var minThltest = (double)SciChartSurface.XAxis.VisibleRange.Min;
    var maxThlTest = (double)SciChartSurface.XAxis.VisibleRange.Max;

    ...

    using (SciChartSurface.SuspendUpdates())
    {

        BackgroundImageAnnotation backgroundImage = null;
        if (backgroundImage == null)
        {
            backgroundImage = new BackgroundImageAnnotation
            {
                CoordinateMode = AnnotationCoordinateMode.Relative,
                X1 = 0,
                Y1 = 0,
                AnnotationCanvas = AnnotationCanvas.BelowChart,
            };
        }

        var mainWindow = Application.Current.MainWindow;
        ....
  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.