Pre loader

Select series via ViewModel

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

0
0

Hi,

I have 4 or 8 series on screen and I want to select 1 of them to display some info about it.

How can I use the SeriesSelectionModifier with MVVM and also change the color of the selected serie.
Is it also possible to get an event when the selection has been changed?

I started with:

SeriesSelectionModifier seriesSelectionModifier = new SeriesSelectionModifier();
this.ChartModifier.ChildModifiers.Add(seriesSelectionModifier);

But don’t know how to continue.

Thanks in advance,
Egbert

  • You must to post comments
1
0

Hello,

First of all, SeriesSelectionModifier is used for selecting series on chart by mouse. If you want select series from ViewModel, you just need to set IsSelected=True for this series(IsSelected is defined in IRenderableSeries). There is also SelectedSeriesStyle property, so you should set SeriesColor to color value you want to have when the series is selected there. Also IRenderableSeries has defined SelectionChanged event, and there is SelectedRenderableSeries property of type ObservableCollection defined in SciChartSurface, so you can subscribe to listen SelectionChanged event for each of the renderable series, or to CollectionChanged event of SelectedRenderableSeries (you need to have such a property in your ViewModel and bind it by One-way binding to surface’s property).

Therefore, what we have:

  1. You need SeriesSelection modifier only if you want to select series by mouse – and can add it either in Xaml or VM
  2. To select series from VM you need to set IsSelected=True
  3. Put all values which you want to have in selected series to Style and set it to SelectedSeriesStyle property – it is applied automatically when IsSelected=True
  4. you can subscribe to SelectionChanged event for each renderable series you have, either to CollectionChanged event of SelectedRenderableSeries property of SciChartSurface.

Please, don’t hesitate to ask if you have any questions!

Best regards,
Yuriy

  • EJansen
    Hi, We want to select the series by mouse and add them in the VM. At the moment I'm only using the following two lines of code: SeriesSelectionModifier seriesSelectionModifier = new SeriesSelectionModifier(); this.ChartModifier.ChildModifiers.Add(seriesSelectionModifier); What extra lines of code do I need to add this modifier to the RenderableSeries and set the selected serie style to a white line color? Thanks again...
  • You must to post comments
0
0

Hi,

Please try out attached solution. Is this what are you looking for?

Best regards,
Yuriy

  • EJansen
    Hi, Yes, with a little bit of tweaking I did get it working. Thanks...
  • You must to post comments
0
0

this example is a but dated. I have a button on my legend that is intended to allow the users to select all the series or deselect all the series. the button essentially goes through the renderable series view models and set the IsSelected to either true or false, this approach doesnt work. what is the best solution to accomplish this?

  • Andrew Burnett-Thompson
    Hi Joseph, Yes very out of date! A 6-yr old forum post. If you are using the new SeriesBinding Api available in SciChart v5 then you want to set BaseRenderableSeriesViewModel.IsSelected = true. You will have to iterate all series and set this value to true on all. If you are using series from code-behind then setting BaseRenderabieSeries.IsSelected = true.
  • Joseph McClean
    hi Andrew thanks for the fast response this was actually a post that i looked at to try to solve my problem ,my question i posted is here: https://www.scichart.com/questions/question/toggle-select-deselect-all-legend-items. I will try what you suggested and see if that works! i am actually using V4.
  • Joseph McClean
    Hi Andrew i reviewed my code and i am doing what you are suggesting but the View isn’t updating to show the selected/de-selected series. I have a code snippet below, is there anything that i am missing? XAML <s:SciChartSurface Name="sciChart" Grid.Row="1" Margin="5" RenderableSeries="{s:SeriesBinding RenderableSeriesViewModels, UpdateSourceTrigger=PropertyChanged}" behavior:AxesCollectionBehaviour.AxisSource="{Binding YAxisViewModels}" VM if (RenderableSeriesViewModels != null && RenderableSeriesViewModels.Any()) { foreach(var series in RenderableSeriesViewModels) { series.IsSelected = !series.IsSelected ; } } Thanks, Joseph
  • You must to post comments
Showing 3 results
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