Reputation: 1
I am building an app which displays a curve in 2D like for example the Math.Sin curve. 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.
Upvotes: 0
Views: 309
Reputation: 18153
As you have already assumed, you can begin by using the same instance of the Form which displays the PlotView. You could expose a method Update
in the PlotDisplayWindow
Form, which would then update the plot view with new points. 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. 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.
Upvotes: 0