鼠标滚轮时 oxyplot 轴锁定中心
oxyplot axis locking center when mouse wheel
我是 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。
我是 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。