Bra*_*ler 2 c# graphing controls winforms oxyplot
我想在我的Windows窗体中停靠一个OxyPlot图并绘制函数图y = 2x - 7
.我已经下载了OxyPlot并添加了对我项目的引用.我使用以下代码将绘图添加到我的表单:
public partial class GraphForm : Form
{
public OxyPlot.WindowsForms.Plot Plot;
public Graph()
{
InitializeComponent();
Plot = new OxyPlot.WindowsForms.Plot();
Plot.Model = new PlotModel();
Plot.Dock = DockStyle.Fill;
this.Controls.Add(Plot);
Plot.Model.PlotType = PlotType.XY;
Plot.Model.Background = OxyColor.FromRgb(255, 255, 255);
Plot.Model.TextColor = OxyColor.FromRgb(0, 0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,我看到白色背景,控件已创建,但它只是一个白色背景.我环顾了OxyPlot.Plot
班上的成员,但我找不到办法来解决问题.如何在图表中绘制方程式?
您需要添加一些数据才能显示,您可以将其添加到Models Series属性中.
线(X,Y)图示例.
public Graph()
{
InitializeComponent();
Plot = new OxyPlot.WindowsForms.Plot();
Plot.Model = new PlotModel();
Plot.Dock = DockStyle.Fill;
this.Controls.Add(Plot);
Plot.Model.PlotType = PlotType.XY;
Plot.Model.Background = OxyColor.FromRGB(255, 255, 255);
Plot.Model.TextColor = OxyColor.FromRGB(0, 0, 0);
// Create Line series
var s1 = new LineSeries { Title = "LineSeries", StrokeThickness = 1 };
s1.Points.Add(new DataPoint(2,7));
s1.Points.Add(new DataPoint(7, 9));
s1.Points.Add(new DataPoint(9, 4));
// add Series and Axis to plot model
Plot.Model.Series.Add(s1);
Plot.Model.Axes.Add(new LinearAxis(AxisPosition.Bottom, 0.0, 10.0));
Plot.Model.Axes.Add(new LinearAxis(AxisPosition.Left, 0.0, 10.0));
}
Run Code Online (Sandbox Code Playgroud)
这个例子: