SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
How to move chart scroll by arrow key? For example, When I pressed the Right Arrow Key, the bars in the chart will move Right one Bar position, vice versa. Thanks.
Hello and thanks for your enquiry!
We had a similar request a while back asking for key bindings to move the RolloverModifier line one step to the left or right. Please take a look here.
If you were to create a similar CustomModifier except you updated the XAxis.VisibleRange you could achieve scrolling, for instance:
public class ScrollWithArrowKeysModifier : ChartModifierBase { void KeydownRolloverModifier_PreviewKeyDown(object sender, KeyEventArgs e) { int pointsToScroll; if (e.Key == Key.Right) { pointsToScroll = 1; } if (e.Key == Key.Left) { pointsToScroll = -1; } // This code assumes you are using a CategoryDateTimeAxis. If not then you will need to adjust it var inputRange = ParentSurface.XAxis.VisibleRange as IndexRange; var outputRange = new IndexRange(inputRange.Min + pointsToScroll, inputRange.Max + pointsToScroll); ParentSurface.XAxis.VisibleRange = outputRange; } public override void OnAttached() { base.OnAttached(); var scichart = (ParentSurface as SciChartSurface); scichart.FindLogicalParent<Window>().PreviewKeyDown += new KeyEventHandler(KeydownRolloverModifier_PreviewKeyDown); } public override void OnDetached() { // Todo: You might want to unsubscribe to PreviewKeyDown here } }
The above should work – let me know if it helps!
Also note in SciChart 2 we have introduced an additional API, which allows you to get a helper class off an axis to perform VisibleRange manipulations.
Try this code out:
IAxisInteractivityHelper axisHelper = ParentSurface.XAxis.GetCurrentInteractivityHelper(); IRange outputRange = axisHelper.ScrollBy(inputRange, pointsToScroll); ParentSurface.XAxis.VisibleRange = outputRange;
I hope this helps!
Andrew
Please login first to submit.