Pre loader

Not able to add Text Annotation to annotation collection.

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

0
0

I have bound the annotation collection to the scichart as shown below.

Annotations="{s:AnnotationsBinding ChartAnnotations}"

And in the code behind (view model) i am adding annotations to the collection like,

   private AnnotationCollection _ChartAnnotations = new AnnotationCollection();
   public AnnotationCollection ChartAnnotations
   {
      get { return _ChartAnnotations; }
      set
      {
         if (_ChartAnnotations == value)
            return;

         _ChartAnnotations = value;
         OnPropertyChanged("ChartAnnotations");
      }
   }

   TextAnnotation annotation = new TextAnnotation();
   annotation.X1 = FirstX;
   annotation.Y1 = 2.0;
   annotation.Text = tempData1[(i - 1) >= 0 ? (i - 1) : 0].PacketType.ToString();
   ChartAnnotations.Add(annotation);

But I am not getting any annotation when I run it, moreover, the original scichart series is also getting disturbed.

Would be grateful if you look into the issue.
Thanks

Version
5.1.0.11299
  • You must to post comments
0
0

Hi there,

Thank you for your question!

The AnnotationsBinding Markup Extension must be bound to a collection of IAnnotationViewModel

Like this:

 <s:SciChartSurface Annotations="{s:AnnotationsBinding Annotations}">

 </s:SciChartSurface>

public class MainViewModel : BindableObject
{
    private ObservableCollection<IAnnotationViewModel> _annotations = new ObservableCollection<IAnnotationViewModel>();

    public MainViewModel()
    {
        Annotations.Add(new LineAnnotationViewModel()
        {
           X1 = 1, X2 = 2, Y1 = 1, Y2 = 2,
           XAxisId = AxisBase.DefaultAxisId,
           YAxisId = AxisBase.DefaultAxisId,
           CoordinateMode = AnnotationCoordinateMode.Relative,
           DragDirections = XyDirection.XYDirection,
           ResizeDirections = XyDirection.XYDirection,
           StrokeThickness = 2, 
           Stroke = Colors.Red,
        });
        ... 
    }

    public ObservableCollection<IAnnotationViewModel> Annotations {  get { return _annotations; } }                
}

Please see our Annotations MVVM API Documentation for more details.

Best regards,
Andrew

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