【问题标题】:Using OxyPlot in WindowsForms在 WindowsForms 中使用 OxyPlot
【发布时间】:2015-06-18 19:25:13
【问题描述】:

到目前为止,从我在 OxyPlot 文档中看到的内容来看,没有太多内容。如何获取 x-y 点并使用 OxyPlot 绘制它们?

这是我尝试取两个点并将它们绘制成图表:

var dataModel = new PlotModel { Title = "data plot" };

foreach (var pt in dataProfile)
{
    XYData.Text = String.Format("X:{0} Y:{1}", pt.X,pt.Y);
    dataModel.Series.Add(pt.X, pt.Y); //(obviously wrong here)
    this.plot1.Model = dataModel;
}

我需要更改/添加到:dataModel.Series.Add(pt.X, pt.Y);,以便它加分?此外,如何随时间绘制点? (x-y,随着时间 t 的过去而绘制)

有谁知道一个好的 OxyPlot 教程网站(用于 WinForms),因为我找不到(除了 OxyPlot 文档,它充其量是非常广泛的)。

【问题讨论】:

  • 你在开玩笑吧? github上有大量示例:github.com/oxyplot/oxyplot/tree/develop/Source/Examples
  • @B.K.我不骗你。在 Windows 窗体示例下查看,只有两个......这两个甚至都与我正在尝试做的事情无关。如果您无法提供帮助,请继续浏览。
  • @John:您不需要所有示例的 WinForms 版本,只需要显示如何将其添加到 WinForm 的版本。数据模型是一样的……

标签: c# winforms oxyplot


【解决方案1】:

我知道您提到了WinForms,但您必须能够熟悉查看所有示例和所有源代码,无论使用何种 UI 框架。在您最喜欢的搜索引擎中查找 oxyplot,您会在他们的 GitHub 页面上找到大量示例(或者在查看此答案时他们将使用的任何 repo 服务)。

无论如何,您想要的是ScattierSeries 情节。然后你给它加点。一个例子:

    public static PlotModel ExampleScatterSeriesPlot()
    {
        var plotModel1 = new PlotModel();
        plotModel1.Subtitle = "The scatter points are added to the Points collection.";
        plotModel1.Title = "ScatterSeries";
        var linearAxis1 = new LinearAxis();
        linearAxis1.Position = AxisPosition.Bottom;
        plotModel1.Axes.Add(linearAxis1);
        var linearAxis2 = new LinearAxis();
        plotModel1.Axes.Add(linearAxis2);
        var scatterSeries1 = new ScatterSeries();
        scatterSeries1.Points.Add(new ScatterPoint(0.667469348137951, 0.701595088793707));
        scatterSeries1.Points.Add(new ScatterPoint(7.74765135149828, 5.11139268759237));
        scatterSeries1.Points.Add(new ScatterPoint(7.97490558492714, 8.27308291023275));
        scatterSeries1.Points.Add(new ScatterPoint(1.65958795308116, 7.36130623489679));
        scatterSeries1.Points.Add(new ScatterPoint(2.6021636475819, 5.06004851081411));
        scatterSeries1.Points.Add(new ScatterPoint(2.30273722312541, 3.87140443263175));
        scatterSeries1.Points.Add(new ScatterPoint(2.15980615101746, 0.208108848989061));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(0.667469348137951, 0.701595088793707));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(7.74765135149828, 5.11139268759237));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(7.97490558492714, 8.27308291023275));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(1.65958795308116, 7.36130623489679));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(2.6021636475819, 5.06004851081411));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(2.30273722312541, 3.87140443263175));
        scatterSeries1.ActualPoints.Add(new ScatterPoint(2.15980615101746, 0.208108848989061));
        plotModel1.Series.Add(scatterSeries1);
        return plotModel1;
    }

在我给你的示例浏览器链接下有大量示例。上面的代码是从那里剪下来的。因此,研究所有可用的选项。 OxyPlot 非常灵活,我已经能够在我最近的项目中轻松扩展它。

【讨论】:

  • 谢谢!您的回答恰好比我浏览的示例更有帮助。
  • @John 没问题。如果这回答了您的问题,请不要忘记将其标记为答案。
  • 您发布的链接指向一个以动物为主题的日本网站
  • @t0b4cc0 这就是五年多后发生的事情。他们搬到了 github——很容易被发现。
  • 我知道这就是我发表评论的原因,因此我们不会被重定向到潜在的恶意网站。感谢您更改链接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-10
相关资源
最近更新 更多