I have a ItemsControl which shows line charts in a vertical uniform grid. Currently they all share the same Annotations collection. The thing I am looking for is if there is a way to control which graph the annotation will show up on. Currently if I add a Text annotation to the collection it shows up on all of the graphs. But it works fine when added a vertical line annotation where I want it to show up on all graphs. I also have the need for a vertical line annotation to show up on only one graph though. If there is not a way to control this what would be the best solution for this?
Thank You
Todd
- Todd Stewart asked 5 years ago
- You must login to post comments
Hi Todd,
Sounds like what you’ve done is share annotations across charts, which is not permitted for the following reason:
related question https://www.scichart.com/questions/question/share-annotations-between-a-few-chartsurfaces
There is no way to share annotations between different chart surfaces,
because they are UIElements. This is a WPF limitation, not SciChart
limitation – a UIElement can only have one parent.What I would suggest you do is follow the guidance in our
documementation for using Annotations in MVVM:Then, you can have one
set of ViewModels and duplicate the annotations on charts.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 5 years ago
- You must login to post comments
No this is not the issue I am running into. I am using mvvm for setting up the graphs.
In Model
public ObservableCollection<BaseAnnotationViewModel> Annotations { get; } = new ObservableCollection<BaseAnnotationViewModel>();
XAML is in the image
This is how I add the Vertical Line Annotation
var TheAnnotation = new VerticalLineAnnotationViewModel()
{
X1 = 1000,
Stroke = Colors.Red,
IsEditable = true,
ShowLabel = true,
LabelPlacement = LabelPlacement.Axis,
};
So each graph gets the same annotations. If I added a vertical line to the Annotations it gets added to each graph and if it is moved it is synced across all charts. This works fine if the Annotation I want to add needs to be on all charts. With this method there is no way to add an annotation to just one chart surface. That is what I am trying to solve.
I have also setup a test app where each graph gets its own collection of annotations which works fine for annotations for each individual graph but when added a vertical line that needs to be on each graph it does not stay synced. Just trying to find the best way to handle this, not sure if something had already been done.
Todd
- Todd Stewart answered 5 years ago
- last edited 5 years ago
-
OK in this case Im guessing that your two charts share the same ViewModel and hence same collection of IAnnotationViewModels. In this case — this is expected behaviour. You need to have separate collections (or separate ViewModels) if you want each chart to have its own set of annotations. Please provide more code to explain how you’ve setup the chart if you require further diagnosis. Best regards, Andrew
- You must login to post comments
Please login first to submit.