Dear all,
Actually in all chart demo the zoom is done by using the mouse and define the area to zoom in.
I would like to be able to have a button when I click on it it will zoom the view port area with a predifine zoom increment.
Question :
How can we control the zoom from a button click without specifying an area but use a zoom increment instead ?
thanks sample
regards
- sc sc asked 6 years ago
- You must login to post comments
Sure you can, you can zoom programmatically with SciChart WPF.
Please see the article Programmatically Zoom, Scroll an Axis for more information
Example
A simple example below shows how you can use Axis.Zoom() in combination with the ChartModifierBase API to create a simple custom modifier which handles KeyDown and zooms in and out on CTRL+ or CTRL- Key Presses.
Include this on your chart like any other modifier, by setting SciChartSurface.ChartModifier = new SimpleZoomInOutModifier();
/// <summary>
/// A single X-Y axis implementation of a Zooming In / Out on KeyDown (CTRL+, CTRL-), used to demonstrate the ChartModifierBase and Axis Interactivity APIs in SciChart
/// </summary>
public class SimpleZoomInOutModifier : ChartModifierBase
{
public static readonly DependencyProperty ZoomFractionProperty = DependencyProperty.Register("ZoomFraction", typeof (double), typeof (SimpleZoomInOutModifier), new PropertyMetadata(0.1));
public double ZoomFraction
{
get { return (double) GetValue(ZoomFractionProperty); }
set { SetValue(ZoomFractionProperty, value); }
}
void SciChart_PreviewKeyDown(object sender, KeyEventArgs e)
{
double factor = 0;
if (e.Key == Key.Add && (Keyboard.Modifiers & ModifierKeys.Control) > 0)
{
// On CTRL+, Zoom In
factor = -ZoomFraction;
}
if (e.Key == Key.Subtract && (Keyboard.Modifiers & ModifierKeys.Control) > 0)
{
// On CTRL-, Zoom Out
factor = ZoomFraction;
}
using (ParentSurface.SuspendUpdates())
{
// Zoom the XAxis by the required factor
XAxis.ZoomBy(factor, factor, TimeSpan.FromMilliseconds(500));
// Zoom the YAxis by the required factor
YAxis.ZoomBy(factor, factor, TimeSpan.FromMilliseconds(500));
// Note.. can be extended for multiple YAxis XAxis, just iterate over all axes on the parent surface
}
}
public override void OnAttached()
{
base.OnAttached();
var scichart = ((SciChartSurface)ParentSurface);
var mainWindow = FindLogicalParent<Window>(scichart);
mainWindow.PreviewKeyDown -= SciChart_PreviewKeyDown;
mainWindow.PreviewKeyDown += SciChart_PreviewKeyDown;
}
private T FindLogicalParent<T>(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;
}
}
Best regards,
Andrew
- Andrew Burnett-Thompson answered 6 years ago
- You must login to post comments
Please login first to submit.