Issue to retain selected datapoint while switching series at runtime

6 posts, 1 answers
  1. Sivakumar
    Sivakumar avatar
    27 posts
    Member since:
    Dec 2015

    Posted 07 Apr Link to this post

    My chart having logic which switching between Point and Line series at run time.Issue is after switching series chart not retain the selection with new series selected.

     

    Please help to resolve this issue.

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 08 Apr Link to this post

    Hello Sivakumar,

    This behavior is expected because when you switch the series you create a new series object different than the previous one which has different DataPoint models. In order to achieve your requirement you can use the SelectedPoints collection of the chart to save your view models when the old series is removed and when you add the new one you can use the saved models to select the new generated data points.

    Regards,
    Martin
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sivakumar
    Sivakumar avatar
    27 posts
    Member since:
    Dec 2015

    Posted 11 Apr in reply to Martin Link to this post

    I am using same data-point model only.I am just switching the series.I am saving currently selected data point model but i am not sure under which event i can assign this saved data model when new series created. I already tried with series created event but there data point not generated yet.please help

    and also chart first series first point need to be selected after chart loaded..please help how to do this also..

    Can you please provide sample code ?

  5. Sivakumar
    Sivakumar avatar
    27 posts
    Member since:
    Dec 2015

    Posted 11 Apr Link to this post

    Please find code below..
     
    private void ChartSeriesProvider_SeriesCreated(object sender, ChartSeriesCreatedEventArgs e)
       {
     
           //todo : retain selected point while switching series
           if (selectedPoint != null)
           {
               var series = selectedPoint.Presenter as CategoricalSeries;
               //var pointToSelect = series.DataPoints[nextSelectedIndex - 1];
           }
     
           //select firstpoint
           if (chart.SelectedPoints.Count == 0)
           {
               var pointToSelect = (e.Series as CategoricalSeries).DataPoints[0];
               pointToSelect.IsSelected = true;
           }
     
       }
    Your quote goes here
  6. Answer
    Martin
    Admin
    Martin avatar
    1101 posts

    Posted 12 Apr Link to this post

    Hello Sivakumar,

    The data points of the series are not yet generated in the SeriesCreated event and this is why you cannot get them. You can use the DataBindingComplete event of the series instead.

    I created a small example demonstrating a possible approach for achieving your requirement. I hope it works for you.

    Regards,
    Martin
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  7. Sivakumar
    Sivakumar avatar
    27 posts
    Member since:
    Dec 2015

    Posted 12 Apr in reply to Martin Link to this post

    Thanks Martin...Your solution is working
Back to Top
UI for WPF is Visual Studio 2017 Ready