繁体   English   中英

如何在 WPF UI 框架上使用 OxyPlot 库绘制 LineSeries

[英]How to plot LineSeries using the OxyPlot library on the WPF UI framework

我正在尝试使用 OxyPlot 绘制我的数据。 我想在我的图中绘制两条线,但我不确定如何为该图提供数据。 这是我的 XAML 文件的样子:

<oxy:Plot Name="Plot1">
  <oxy:Plot.Series>
    <oxy:LineSeries ItemsSource="{Binding Graph1}"/>
    <oxy:LineSeries ItemsSource="{Binding Graph2}"/>
  </oxy:Plot.Series>
</oxy:Plot>

我的问题是如何在使用LineSeries 时在同一图中绘制两条线?

通常您不会将 LineSeries 直接添加到 PlotView,而是添加到 PlotModel,然后绑定到 Plot View。

C# 代码可能如下所示:

        PlotModel pm = new PlotModel();

        var s1 = new LineSeries();

        for (int i = 0; i < 1000; i++)
        {
            double x = Math.PI * 10 * i / (1000 - 1);
            s1.Points.Add(new DataPoint(x, Math.Sin(x)));
        }

        pm.Series.Add(s1);

        var s2 = new LineSeries();

        for (int i = 0; i < 1000; i++)
        {
            double x = Math.PI * 10 * i / (1000 - 1);
            s2.Points.Add(new DataPoint(x, Math.Cos(x)));
        }

        pm.Series.Add(s2);

        Plot1.Model = pm; 

与 Plot1 的绑定当然也可以在 XAML 中完成。 如果您的 DataContext 通过属性“MyModel”提供 PlotModel,它将如下所示:

<oxyplot:PlotView Model="{Binding MyModel}"></oxyplot:PlotView>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM