Pre loader

Getting a selected series and adding a point with a right mouse click (Figured it out. Answer in original post.)

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
1

I’m rebuilding a program to adhere to MVVM and so I’m trying to figure out little tricks to do things I did previously in the code-behind.

I’d like to be able to right-click on a selected series and add a point at that location. I’m doing this in my previous application but I’m not too sure the best route to take with the MVVM application.

I’m currently selecting a series with the SeriesSelectionModifier, but I’m also not sure if there’s a “SelectedSeries” property I can get from the modifier either.

Maybe a Trigger that detects a right mouse click on a selected series that calls a command to add the point?

Or is there just not a way to do this with the chart and I need to rely on subscribing to events?

Thanks!

Answer:

I created a property named SelectedSeries which looks like this…

    public IRenderableSeries SelectedSeries
    {
        get
        {
            if (SciChart.SelectedRenderableSeries.Count > 0)
            {
                return SciChart.SelectedRenderableSeries[0];
            } else
            {
                return null;
            }
        }
    }

Then, I created a MouseRightButtonUp event to see if I right-clicked on SelectedSeries. If so, it adds a point. If I clicked on an existing point, it deletes that point.

    private void _sciChart_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
    {
        if (SelectedSeries != null)
        {
            HitTestInfo hitTestToDelete = SelectedSeries.HitTest(rawPoint: MouseDownPosition, hitTestRadius: 10);

            if (hitTestToDelete.IsHit == true)
            {
                // Do nothing if the first or last point is hit
                if (hitTestToDelete.DataSeriesIndex == 0 || hitTestToDelete.DataSeriesIndex == SelectedSeries.DataSeries.Count - 1)
                {
                    return;
                }

                // Delete point
                DeletePoint(point: hitTestToDelete);
            } else
            {
                // Add point if hitting series
                HitTestInfo hitTestToAdd = SelectedSeries.HitTest(rawPoint: MouseDownPosition, hitTestRadius: 10, interpolate: true);

                if (hitTestToAdd.IsHit == true)
                {
                    // Add point
                    AddPoint(point: hitTestToAdd);
                }
            }
        }
    }
Version
5.3.0.11954
  • Andrew Burnett-Thompson
    Hey Greg, it would greatly improve our forums if you could add a short answer to your own question saying how you figured it out. Thanks!
  • Greg Knox
    Definitely! I should get a chance to do that later today or tomorrow.
  • You must to post comments
Showing 0 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