繁体   English   中英

在Windows窗体应用中使用Oxyplot显示多个LineSeries

[英]Display several LineSeries using Oxyplot in Windows forms app

我正在构建一个应用程序,该应用程序可显示2D曲线,例如Math.Sin曲线。 提示用户输入要在绘图上显示的点数。 当他选择点数并为其输入参数时,将打开一个新窗口,其中显示了绘图。

我的问题是,如果可以的话,我可以返回上一个窗口并输入新参数,该参数将生成一个新曲线,但将其与第一个曲线一起显示吗? 我目前的解决方案是仅显示一条曲线。 任何时候打开Plot窗口-创建它的一个新实例,所以我想我必须找到一种使用同一实例的方法,因为该窗口没有关闭,只有隐藏,但我不知道如何。

签出以下图片: 在此处输入图片说明

正如您已经假设的那样,您可以使用显示PlotView的Form的相同实例开始。 您可以在PlotDisplayWindow窗体中公开方法Update ,该方法随后将使用新的点更新绘图视图。 例如,以您的父母形式。

PlotDisplayWindow plotDisplay;

private void RefreshPlot(object sender, EventArgs e)
{
    var dataPoints = GetNewDataPoints();
    if (plotDisplay == null)
    {
        plotDisplay = new PlotDisplayWindow();
        plotDisplay.Show();
    }
    plotDisplay.Update(dataPoints);
}

在您的PlotDisplayWindow窗体中,您可以在首次加载Window时初始化您的模型,然后使用Update方法将更多点添加到Plot View。 例如:

private void PlotDisplayWindow_Load(object sender, EventArgs e)
{
    this.plotView1.Model = new PlotModel { Title = "Example 1" };
}

public void Update(IEnumerable<DataPoint> points)
{
    this.plotView1.Model.Series.Add(new LineSeries { ItemsSource = points });
    this.plotView1.InvalidatePlot(true);
}

PlotView.InvalidatePlot(true)将确保刷新图并显示新添加的点。

暂无
暂无

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

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