I have a bit of a challenge with annotations. I am running an mvvm application in which you can create annotations dynamically. I can’t seem to get a grip on how to manage these in a good way. My current “workaround” is to handle onAnnotationCreated and use that to add an object to my viewmodel. But then, as my underlying data changes the chart gets redrawn so I need to handle a load event on the scichart and then redraw them based on the information in my view model. Any thoughts on a better way to solve this?
However now the story gets even more interesting. I need to give my users the option of changing color, stroke and such on these annotations. How could I do this? And then how would I manage to keep my viewmodel updated with these changes?
AnnotationCreationModifier is really added as a guideline on how to user-add annotations. Since you have the source code (thanks for upgrading btw!) why not create your own custom modifier which instead of adding to the SciChartSurface.Annotations collection, it handles mouse events and adds new AnnotationViewModels?
E.g. your architecture becomes something like this (refer to attached image)
Draws charts, annotations as normal. Binds to ChartViewModel which contains series data
Has 1..N AnnotationViewModels which have properties such as Color, Text, Position or other custom properties. Maybe you have a number of annotation view models such as TextAnnotationViewModel, LineAnnotationviewModel if you are mixing types
Databinds to ChartViewModel.Annotations and consumes annotationViewModels. Adds or maintains the state of 1..N annotations on the parent SciChartSurface. Only concerned with the presentation / rendering. Use the modifier from our MVVM Annotations tutorial as a basis for this.
This class listens to mouse events e.g. two clicks. As the user is placing the two clicks (use our code from AnnotationCreationModifier as a basis for this) it places the line annotation on the chart. Then on completion, it removes that and creates an AnnotationViewModel to represent it. Because of databinding magic and because of the rendering modifier this will get picked up and added to the chart surface.
And hey presto, you have user-creatable annotations plus state management, colours, custom properties in a viewmodel!
Hope this helps,
Please login first to submit.