Pre loader

How to improve performance when reloading annotations

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

Answered
1
0

Hello!
I’ m working with big number of annotations. They’re creating an image of earth section profile. We need to recreate them everytime, when visible range changed. For these purposes we use MouseWheelZoom and ZoomPanModifier. And when go to another region of our image or zoom it,it flickers. I had a thought that the problem was that I deleted all annotations and the duration between deleting old and creating new was that flicker. I rewrited the code so he added annotation at first and then deleted old annotations. Here is it:

            foreach (var mainSectLine in mainSectLines)
            {
                Color tempColor = new Color();
                double temp = mainSectLine.val/maxValueForPainting;
                if (temp < 0.2) tempColor = Colors.Blue;
                else
                {
                    if (temp < 0.4) tempColor = Colors.Green;
                    else
                    {
                        if (temp < 0.6) tempColor = Colors.Yellow;
                        else
                        {
                            if (temp < 0.8) tempColor = Colors.Orange;
                            else
                            {
                                tempColor = Colors.Red;
                            }
                        }
                    }
                }

                var tempBrush = new SolidColorBrush(tempColor);
                if (tempBrush.CanFreeze)
                {
                    tempBrush.Freeze();
                }
                LineAnnotationItem lineAnnotation = new LineAnnotationItem()
                {
                    Index = Index,
                    X1 = mainSectLine.THL1,
                    X2 = mainSectLine.THL2,
                    Y1 = -mainSectLine.TVD1,
                    Y2 = -mainSectLine.TVD2,
                    YAxisId = textOfYAxis,
                    Stroke = tempBrush,
                    AnnotationCanvas = AnnotationCanvas.BelowChart,
                };
                AnnotationCollection.Add(lineAnnotation);
            }
            List<IAnnotation> annotationsToDelete =
                AnnotationCollection.Where(q => q.GetType() == typeof (LineAnnotationItem)&&((LineAnnotationItem)q).Index==Index-1).ToList();
            foreach (IAnnotation annotation in annotationsToDelete)
            {
                AnnotationCollection.Remove(annotation);
            }

But that does not make a sense. So it also took a lot of time to detach and attach annotations. To solve that trouble, I rewrited function:

List<IAnnotation> annotations =
                AnnotationCollection.Where(q => q.GetType() != typeof (LineAnnotationItem)).ToList();
            AnnotationCollection tempAnnotationCollection=new AnnotationCollection();
            foreach (var mainSectLine in mainSectLines)
            {
                Color tempColor = new Color();
                double temp = mainSectLine.val/maxValueForPainting;
                if (temp < 0.2) tempColor = Colors.Blue;
                else
                {
                    if (temp < 0.4) tempColor = Colors.Green;
                    else
                    {
                        if (temp < 0.6) tempColor = Colors.Yellow;
                        else
                        {
                            if (temp < 0.8) tempColor = Colors.Orange;
                            else
                            {
                                tempColor = Colors.Red;
                            }
                        }
                    }
                }

                var tempBrush = new SolidColorBrush(tempColor);
                if (tempBrush.CanFreeze)
                {
                    tempBrush.Freeze();
                }
                LineAnnotationItem lineAnnotation = new LineAnnotationItem()
                {
                    Index = Index,
                    X1 = mainSectLine.THL1,
                    X2 = mainSectLine.THL2,
                    Y1 = -mainSectLine.TVD1,
                    Y2 = -mainSectLine.TVD2,
                    YAxisId = textOfYAxis,
                    Stroke = tempBrush,
                    AnnotationCanvas = AnnotationCanvas.BelowChart,
                };
                tempAnnotationCollection.Add(lineAnnotation);
            }
            AnnotationCollection = tempAnnotationCollection;
            foreach (IAnnotation annotation in annotations)
            {
                AnnotationCollection.Add(annotation);
            }

But there are still flickers when pan or zoom, but it works a bit faster.
So how can I eliminate these flickers? What can I do to speed up adding and deleting annotations?

  • You must to post comments
Best Answer
1
0

Hi Ilya,

Another user reported being able to show up to 50,000 annotations on a SciChartSurface. He also had similar performance problems to yourself, but we suggested this workaround to reload annotations into a detached AnnotationCollection then attach the whole collection once to the SciChartSurface.

There is a code sample in the Performance with Lots of Annotations answer.

Hope this helps!

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies