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
- Ashvij asked 6 years ago
- last edited 6 years ago
- You must login to post comments
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
- Andrew Burnett-Thompson answered 6 years ago
-
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.
-
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
-
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.
-
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}”?
-
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?
- 4 more comments
- You must login to post comments
Please login first to submit.