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!

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.

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

  • Ashvij
    From the testing that I have done till now, one thing I got to know is that if I add the annotations in the constructor of my view model , it works fine, but if I add the annotations in my timer function (in a loop) it won’t work.
  • Andrew
    It shouldn’t matter where you add them. I would suggest following our tutorial on adding annotations with mvvm to better understand this api https://www.scichart.com/documentation/v5.x/Tutorial%2007b%20-%20Adding%20Annotations%20with%20MVVM.html
  • Ashvij
    Thanks for the help. I think the problem is that I want to add a collection of annotations every time I update the line series in a timer (dynamically) and I guess that is not possible with annotations in scichart.
  • Ashvij
    I had one small query… In the tutorial 07b – Adding Annotations with MVVM , how is the ObservableCollection(IAnnotationViewModel) Annotations bound to xaml code, cause I am getting a blank scichart surface on adding the annotations through this – Annotations=”{s:AnnotationsBinding Annotations}”?
  • Andrew
    Blank chart can be debugged by going through our troubleshooting. http://support.scichart.com/index.php?/Knowledgebase/Article/View/17247/36/help-my-chart-is-blank-why-doesnt-scichart-render. The tutorial code works so there must be a problem on your side?
Showing 1 result
Your Answer

Please first to submit.