Hello support team,
Im looking for a way to use keys to navigate through values in the graph. The rollover provides this easily with the mouse.
I include the rollovermodifier and the template I have. Do you have an idea how to do this? I just need to navigate left and right with the cursors. Any input or idea is extremely welcome.
Thank you very much for your great support
Marcel
- Marcel asked 11 years ago
- You must login to post comments
Hi Marcel,
Keyboard input for ChartModifiers is a hotly requested feature. We haven’t implemented this yet, but you can achieve the same effect by a workaround.
Start by inheriting RolloverModifier and subscribing to the KeyDown event of the parent Window. E.g.
public class KeydownRolloverModifier : RolloverModifier { private double positionFraction = 0.0; void KeydownRolloverModifier_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Right) { positionFraction += 0.01; } if (e.Key == Key.Left) { positionFraction -= 0.01; } // Constrain to 0.0, 1.0 positionFraction = positionFraction > 1.0 ? 1.0 : positionFraction < 0.0 ? 0.0 : positionFraction; UpdateRollover(positionFraction); } public override void OnAttached() { base.OnAttached(); var scichart = (ParentSurface as SciChartSurface); scichart.FindLogicalParent<Window>().PreviewKeyDown += new KeyEventHandler(KeydownRolloverModifier_PreviewKeyDown); } public override void OnModifierMouseMove(ModifierMouseArgs e) { // Don't call base. This way the mouse does not change the cursor position // base.OnModifierMouseMove(e); } private void UpdateRollover(double fraction) { var point = new Point(ModifierSurface.Width * fraction, 0); point = ModifierSurface.TranslatePoint(point, RootGrid); base.OnModifierMouseMove(new ModifierMouseArgs(point, MouseButtons.None, MouseModifier.None, true)); } }
The code for FindLogicalParent is as follows:
public static class FrameworkElementExtensions { public static T FindLogicalParent<T>(this FrameworkElement element) where T : FrameworkElement { var parent = (FrameworkElement)element.Parent; if (parent is T) return (T)parent; return parent.FindLogicalParent<T>(); } }
Using the above you should get a key right/left response by moving the rollover. It’ll move by a percentage each time, not to the next data-point. If you wish to achieve data-point by point moves, then maybe take a look at the HitTest API (BaseRenderableSeries.HitTest). This is used in the base RolloverModifier class to get the X,Y values of data-points.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 11 years ago
- You must login to post comments
Please login first to submit.