限制 DateTime 轴上的缩放
Limit zoom on DateTime axis
我正在将 SciChart 与 DateTimeAxis 一起使用。
我的商品从 2016 年 5 月 15 日 8:30 上午开始,到 2016 年 5 月 25 日 8:30 上午结束。 VisibleRange 的初始值也设置为这个范围。我还再次添加了具有相同范围的 VisibleRangeLimit。
但问题是,当我滚动到角落时,日期值超出了我的范围,因此,在某些缩放级别上,我看到日期超出了我允许的范围,例如 2016 年 5 月 15 日 8:25上午。这导致空白 5 分钟。
有没有办法真正限制可见范围?
是的,
来自Documentation: Clipping the Axis.VisibleRange on Zoom and Pan.
Advanced VisibleRange Clipping and Manipulation
Axis.VisibleRangeLimit is a useful API to ensure the axis clips the VisibleRange when zooming to extents. However, it will not stop a user from scrolling outside of that range. To achieve that, you need a small modification:
Clipping Axis.VisibleRange in Code
To clip the VisibleRange and force a certain maximum or minimum, just use the following code:
axis.VisibleRangeChanged += (s, e) =>
{
// e is VisibleRangeChangedEventArgs
// Assuming axis is NumericAxis
if (e.NewVisibleRange != null && e.NewVisibleRange.Min < 0)
{
// Force minimum visiblerange to zero always
((NumericAxis)sender).VisibleRange = new DoubleRange(0, e.NewVisibleRange.Max);
}
};
Clipping Axis.VisibleRange with MVVM
The same can be achieved in MVVM by creating a custom behavior.
public class AxisClippingBehavior : Behavior<AxisBase>
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.VisibleRangeChanged +=OnVisibleRangeChanged;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.VisibleRangeChanged -= OnVisibleRangeChanged;
}
private void OnVisibleRangeChanged(object sender, VisibleRangeChangedEventArgs visibleRangeChangedEventArgs)
{
var visibleRangeLimit = AssociatedObject.VisibleRangeLimit;
if (visibleRangeLimit != null)
{
var limitMode = AssociatedObject.VisibleRangeLimitMode;
var range = (IRange)AssociatedObject.VisibleRange.Clone();
range.ClipTo(visibleRangeLimit, limitMode);
AssociatedObject.SetCurrentValue(AxisBase.VisibleRangeProperty, range);
}
}
}
我正在将 SciChart 与 DateTimeAxis 一起使用。
我的商品从 2016 年 5 月 15 日 8:30 上午开始,到 2016 年 5 月 25 日 8:30 上午结束。 VisibleRange 的初始值也设置为这个范围。我还再次添加了具有相同范围的 VisibleRangeLimit。
但问题是,当我滚动到角落时,日期值超出了我的范围,因此,在某些缩放级别上,我看到日期超出了我允许的范围,例如 2016 年 5 月 15 日 8:25上午。这导致空白 5 分钟。
有没有办法真正限制可见范围?
是的,
来自Documentation: Clipping the Axis.VisibleRange on Zoom and Pan.
Advanced VisibleRange Clipping and Manipulation
Axis.VisibleRangeLimit is a useful API to ensure the axis clips the VisibleRange when zooming to extents. However, it will not stop a user from scrolling outside of that range. To achieve that, you need a small modification:
Clipping Axis.VisibleRange in Code
To clip the VisibleRange and force a certain maximum or minimum, just use the following code:
axis.VisibleRangeChanged += (s, e) => { // e is VisibleRangeChangedEventArgs // Assuming axis is NumericAxis if (e.NewVisibleRange != null && e.NewVisibleRange.Min < 0) { // Force minimum visiblerange to zero always ((NumericAxis)sender).VisibleRange = new DoubleRange(0, e.NewVisibleRange.Max); } };
Clipping Axis.VisibleRange with MVVM
The same can be achieved in MVVM by creating a custom behavior.
public class AxisClippingBehavior : Behavior<AxisBase> { protected override void OnAttached() { base.OnAttached(); AssociatedObject.VisibleRangeChanged +=OnVisibleRangeChanged; } protected override void OnDetaching() { base.OnDetaching(); AssociatedObject.VisibleRangeChanged -= OnVisibleRangeChanged; } private void OnVisibleRangeChanged(object sender, VisibleRangeChangedEventArgs visibleRangeChangedEventArgs) { var visibleRangeLimit = AssociatedObject.VisibleRangeLimit; if (visibleRangeLimit != null) { var limitMode = AssociatedObject.VisibleRangeLimitMode; var range = (IRange)AssociatedObject.VisibleRange.Clone(); range.ClipTo(visibleRangeLimit, limitMode); AssociatedObject.SetCurrentValue(AxisBase.VisibleRangeProperty, range); } } }