【问题标题】:Render OxyPlot graph in Windows Form在 Windows 窗体中渲染 OxyPlot 图
【发布时间】:2013-01-18 01:37:27
【问题描述】:

我想在我的 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);
    }
}

使用这段代码,我看到了白色背景,控件已经创建,但它只是一个白色背景。我环顾了OxyPlot.Plot 类的成员,但找不到一种方法来制定我的方程式。如何在图表中绘制我的方程?

【问题讨论】:

    标签: c# winforms controls graphing oxyplot


    【解决方案1】:

    您需要添加一些数据来显示,您将其添加到模型系列属性中。

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

    这个例子:

    【讨论】:

    • 用更好的例子更新
    • 我不想制作条形图。我正在尝试绘制一条线。我需要绘制函数y = 2x - 7,这是一个斜率截距形式的方程。条形图对我没有帮助,因为我不能简单地将数据手动添加到图表中。线上的每个点都是数据,我不可能单独添加这些点。我想在图中画一条线,就像你在高中的代数中一样。
    • 哦,我看到你已经更新了。让我看看我能用你的例子做什么。
    • 是的,你只需要按照你想要的方式设置轴,我只是设置了轴最小值/最大值,你可以删除它们,或者添加你自己的值,有一堆示例应用程序在 Oxplot 网站上。oxyplot.codeplex.com/releases/view/76035
    • @Brandon Miller:您可以通过将PositionAtZeroCrossing 属性设置为true 来使轴以这种方式显示。请参阅oxyplot.org/examplebrowser,特别是“轴示例”部分中的“零交叉轴”。
    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    • 2011-07-21
    • 2018-11-06
    • 2014-12-21
    • 1970-01-01
    相关资源
    最近更新 更多