Pre loader

Editing annotations and keeping track of them in an mvvm application

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

Answered
1
0

Hi guys!

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?

  • You must to post comments
Best Answer
3
0

Hi Lisbeth,

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)

SciChartSurface

Draws charts, annotations as normal. Binds to ChartViewModel which contains series data

ChartViewModel

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

CustomAnnotationRenderingModifier

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.

CustomAnnotationCreationModifier

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,
Andrew

Images
  • Andrew Burnett-Thompson
    Ok, have you tried a TwoWay binding on X1,Y1,X2,Y2 properties to the viewmodel properties? This *should* theoretically work although we've not testing it - you're the annotation expert now! ;-)
  • Lisbeth Skogland
    Now this was strange... that was about the last thing I tried before posting and it didn't work. Now all of a sudden it does, must have been a rebuild issue of some sort... anyway, looks like I have everything I need now to finish the features then. Thank you so much for your input, you probably saved a lot of hours on this. Lisbeth
  • Andrew Burnett-Thompson
    No problem at all, if we can save our customers a couple of hours then we're doing our jobs & adding value! BTW your example reminded me to create a tutorial on this topic. We're pretty busy at the moment but maybe after things settle down with our next version it could be a good time to do it. So thanks - appreciate jogging my memory! Andrew
  • Abhilash R
    Hi Lisbeth/ Andrew Could you please share your code ? It will be great if you create a tutorial on this topic.
  • Andrew Burnett-Thompson
    Hi Abhilash, unfortunately we don't have source-code for the above, but we do have an (old) tutorial which gives you the general idea and that is here: https://www.scichart.com/databinding-annotations-with-mvvm. Does this help?
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