当鼠标滚轮时,氧气轴锁定中心

我是wpf和oxyPlot的新手。 现在,我想创建一个像示波器一样的动态折线图,但我不知道如何在鼠标滚轮缩放时将轴锁定在一个值上。

例:

在此处输入图像描述

红点是鼠标位置。 在正常情况下,缩放A – > B,缩放C – > D.现在,我想缩放C – > E,就像鼠标位置在0中心一样。

我找到了一个适用于阻止轴变焦中心的解决方案。 您必须创建自定义LinearAxis才能实现此目的:

 public class FixedCenterLinearAxis : LinearAxis { double center = 0; public FixedCenterLinearAxis() : base(){} public FixedCenterLinearAxis(double _center) : base() { center = _center; } public override void ZoomAt(double factor, double x) { base.ZoomAt(factor, center); } } 

你必须这样使用它:

 var bottomAxis = new FixedCenterLinearAxis(0.5) //specify the center value here { Position = AxisPosition.Bottom, }; plotModel.Axes.Add(bottomAxis); 

如果不在构造函数上指定值,则中心值将为0。

Interesting Posts