我正在创建一个程序,该程序使用btnCalculate_Click
在oxyplot
之后创建一个绘图。我该怎么做,以便每当我更改文本框值并单击btnCalculate
时都可以刷新图?我也有btnPrint
,点击它应该清除情节吗?
public void btnCalculate_Click(object sender, EventArgs e)
{
Pko = float.Parse(textBox5.Text);
//Plotting Using Oxyplots
OxyPlot.WindowsForms.PlotView pv = new PlotView();
pv.Location = new Point(650, 0);
pv.Size = new Size(900, 815);
this.Controls.Add(pv);
pv.Model = new PlotModel { Title = "Program" };
pv.Model.InvalidatePlot(true);
//Pko line from surface to depth
LineSeries Pkoline = new LineSeries();
Pkoline.Color = OxyColors.Black;
Pkoline.LineStyle = LineStyle.Solid;
Pkoline.StrokeThickness = 1;
Pkoline.Points.Add(new DataPoint(Pko, 0));
Pkoline.Points.Add(new DataPoint(100, 200));
pv.Model.Series.Add()
}
private void btnClear_Click(object sender, EventArgs e)
{
}
答案 0 :(得分:1)
首先,您需要为plot定义变量以在不同的事件处理程序中调用它。清除情节就是清除系列收藏
private readonly PlotView _pv;
public Form1()
{
InitializeComponent();
//moved initialization from btnCalculate_Click
_pv = new PlotView();
this.Controls.Add(_pv);
_pv.Location = new Point(0, 0);
_pv.Size = new Size(500, 500);
_pv.Model = new PlotModel {Title = "Program"};
_pv.Model.InvalidatePlot(true);
}
private void btnCalculate_Click(object sender, EventArgs e)
{
// keep old code Except _pv initialization
_pv.Model.Series.Add(Pkoline);//typo in old code
}
private void clearBtn_Click(object sender, EventArgs e)
{
_pv.Model.InvalidatePlot(true);
_pv.Model.Series.Clear();
}