简体   繁体   English

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

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

I am building an app which displays a curve in 2D like for example the Math.Sin curve. 我正在构建一个应用程序,该应用程序可显示2D曲线,例如Math.Sin曲线。 The user is prompted to enter how many dots he wants to display on the plot. 提示用户输入要在绘图上显示的点数。 When he chooses the number of dots and enters the parameters for them - a new window is opened where the plot is displayed. 当他选择点数并为其输入参数时,将打开一个新窗口,其中显示了绘图。

My question is, if there is a way, I can get back to the previous window and enter new parameters which will generate a new curve BUT display it together with the first one? 我的问题是,如果可以的话,我可以返回上一个窗口并输入新参数,该参数将生成一个新曲线,但将其与第一个曲线一起显示吗? My solution for now is for only one curve being displayed. 我目前的解决方案是仅显示一条曲线。 Any time the Plot window is opened - a new instance of it is created, so I suppose I have to find a way to use the same instance since the window is not closed, only hidden, but I dont know how. 任何时候打开Plot窗口-创建它的一个新实例,所以我想我必须找到一种使用同一实例的方法,因为该窗口没有关闭,只有隐藏,但我不知道如何。

Checkout the following image: 签出以下图片: 在此处输入图片说明

As you have already assumed, you can begin by using the same instance of the Form which displays the PlotView. 正如您已经假设的那样,您可以使用显示PlotView的Form的相同实例开始。 You could expose a method Update in the PlotDisplayWindow Form, which would then update the plot view with new points. 您可以在PlotDisplayWindow窗体中公开方法Update ,该方法随后将使用新的点更新绘图视图。 For example, in your parent form. 例如,以您的父母形式。

PlotDisplayWindow plotDisplay;

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

In your PlotDisplayWindow Form, you could initialize your Model when loading the Window for the first time and then, use the Update method to add more points to the Plot View. 在您的PlotDisplayWindow窗体中,您可以在首次加载Window时初始化您的模型,然后使用Update方法将更多点添加到Plot View。 For example: 例如:

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);
}

The PlotView.InvalidatePlot(true) would ensure the plot is refreshed and the newly added points are displayed. PlotView.InvalidatePlot(true)将确保刷新图并显示新添加的点。

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

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