gpt4 book ai didi

c# - 在 Windows 窗体中渲染 OxyPlot 图

转载 作者:行者123 更新时间:2023-12-02 22:16:22 24 4
gpt4 key购买 nike

我想在我的窗口窗体中放置一个 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);
}
}

通过这段代码,我看到了白色背景,控件已经创建,但它只是一个白色背景。我查看了 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));

}

这个例子:

enter image description here

关于c# - 在 Windows 窗体中渲染 OxyPlot 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14391195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com