繁体   English   中英

在按键/鼠标事件后禁用设置OxyPlot PlotView的最大值/最小值

[英]Setting OxyPlot PlotView max/min disabled after key/mouse events

我有一个Wpf应用程序,它显示了plotview,还有一个按钮,该按钮调用一个函数,用于根据其数据自动缩放图表。 我遇到的问题是,如果我使用键盘或鼠标进行平移/缩放与plotview进行交互,则我的自动缩放按钮(仅设置轴的最大值和最小值)不会导致plotview明显改变。 我已经确认在对象本身中已修改了最大值/最小值,但是这些变化未在plotview中显示。

public class ViewModel
{
    public const int maxSamples = 45000;
    public ViewModel()
    {
        this.PlotModel = new PlotModel();

        // the x-axis
        this.PlotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { 
                Position = OxyPlot.Axes.AxisPosition.Bottom, 
                AbsoluteMinimum = 0, 
                AbsoluteMaximum = maxSamples,
                Minimum = 0,
                Maximum = maxSamples
            });

        // the y-axis
        this.PlotModel.Axes.Add(new OxyPlot.Axes.LinearAxis { 
                Position = OxyPlot.Axes.AxisPosition.Left, 
                Minimum = -100, 
                Maximum = 200 
            });
    }

    public PlotModel Ch1Model { get; private set; }

    public void AutoZoom()
    {
        double max;
        double min;

        // some code to determine the max/min values for the y-axis
        // ...

        ((LinearAxis)PlotModel.Axes[1]).Maximum = max;
        ((LinearAxis)PlotModel.Axes[1]).Minimum = min;

        PlotModel.InvalidatePlot(true);
    }
}

同样,调用AutoZoom()一直有效,直到我使用鼠标/键盘与plotview进行交互,然后AutoZoom设置了“轴”上的“最大/最小”值,但显示不会更新。 关于我可能要去哪里的任何想法?

我知道这是一个问题,已经存在了一段时间而没有答案,但是当我遇到同一问题时,我发现它仍然很重要。

Axis对象的内部,有一个ViewMinimumViewMaximum ,它们被初始化为double.NaN 用鼠标平移,缩放等后,这些值将设置为平移/缩放操作结束时的值。 然后,在随后对Axis对象进行任何重绘时,这些值的优先级都高于MinimumMaximum

为了使PlotView遵循指定的MinimumMaximum ,您必须通过调用其Reset()方法来重置轴,然后将值分配给MinimumMaximum 还要注意,一旦将Minimum and Maximum设置为Minimum ,并且将PlotType设置为Cartesian ,OxyPlot将在X和Y轴上使用相同的缩放比例。 要避免这种情况,请将ModelPlotTypePlotType.XY

例如:

public void AutoZoom()
{
    double max;
    double min;

    // some code to determine the max/min values for the y-axis
    // ...

    PlotModel.Axes[1].Reset(); //Reset the axis to clear ViewMinimum and ViewMaximum

    ((LinearAxis)PlotModel.Axes[1]).Maximum = max;
    ((LinearAxis)PlotModel.Axes[1]).Minimum = min;

    PlotModel.InvalidatePlot(true);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM