SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Answered
1
0

Hi,

I am trying out SciChart, and so far I am impressed about the performance and capabilities.

For my application I need to have a cursor showing the X and Y values of the current data point. The RolloverModifier seems to be a good start, but at some points i need other behaviour:

  1. I need the cursor to only move when the mouse button is down. So
    you can zoom/pan the graph, with the cursor remaining on the same
    data point.
  2. I need the cursor to move to the next/previous data
    point on a keypress (Keys.Left and Keys.Right).

The exapmle “Custom ChartModifiers – Part 2 – Custom ZoomPanModifier and Zooming on KeyPress” seems to be a good start, where the OnAttached() method of a SimpleZoomInOutModifier class, derived from ChartModifierBase, is overridden to get access to keypress events:

    public override void OnAttached()
    {
        base.OnAttached();
        var scichart = ((SciChartSurface)ParentSurface);

        var mainWindow = FindLogicalParent(scichart);

        mainWindow.PreviewKeyDown -= SciChart_PreviewKeyDown;
        mainWindow.PreviewKeyDown += SciChart_PreviewKeyDown;
    }

    private T FindLogicalParent(SciChartSurface scichart) where T:class
    {
        var parent = (FrameworkElement)scichart.Parent;
        while (parent != null)
        {
            var candidate = parent as T;
            if (candidate != null) return candidate;

            parent = (FrameworkElement)parent.Parent;
        }

        return null;
    }

But the function FindLogicalParent() gives compiler errors, and in the downloaded code for this exaple application, this method isn’t even there… the method OnAttached() in the downloaded code is:

    public override void OnAttached()
    {
        base.OnAttached();
        var scichart = ((SciChartSurface)ParentSurface);

        scichart.PreviewKeyDown -= SciChart_PreviewKeyDown;
        scichart.PreviewKeyDown += SciChart_PreviewKeyDown;
    }

But this code doesn’t work. The SciChart_PreviewKeyDown eventhandler is never called.

How to move forward?

  • You must to post comments
Good Answer
0
0

Hi Niet,

It sounds to me like what you want is the VerticalSliceModifier:

Adding draggable RolloverModifier style lines with the VerticalSliceModifier

What does the VerticalSliceModifier do?
The VerticalSliceModifier allows showing one or more vertical lines on
the chart and a tooltip on data-points of all series under the line.
The VerticalSliceModifier is very similar in behaviour to the
RolloverModifier, but allows one or more lines to be positioned and
optionally dragged by the user.

enter image description here

Let me know if this helps!

Best regards,
Andrew

  • You must to post comments
0
0

That’s great indeed. Thanks.

Still need to control the cursor using the keyboard… any hints?

  • Andrew
    Hi Niet, Since the VerticalSliceModifier.VerticalLines property is exposed, you can simply handle Window.KeyDown / KeyUp and increment VerticalLineAnnotation.X1 to move the line. The selected line is denoted by VerticalLineAnnotation.IsSelected. Hope this helps,
  • Niet Herkenbaar
    Thanks again Andrew. That works for me.
  • Andrew
    Great! Glad to be of help. Best regards, Andrew
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.