[英]How to plot LineSeries using the OxyPlot library on the WPF UI framework
I am trying to plot my data using OxyPlot.我正在尝试使用 OxyPlot 绘制我的数据。 I want to plot two lines in my graph but I am not sure how to provide the plot with data.我想在我的图中绘制两条线,但我不确定如何为该图提供数据。 This is how my XAML file looks like:这是我的 XAML 文件的样子:
<oxy:Plot Name="Plot1">
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding Graph1}"/>
<oxy:LineSeries ItemsSource="{Binding Graph2}"/>
</oxy:Plot.Series>
</oxy:Plot>
My question is how can I plot two lines in the same graph while using LineSeries ?我的问题是如何在使用LineSeries 时在同一图中绘制两条线?
Usually you don't add the LineSeries directly to a PlotView but to a PlotModel which is then bound to the Plot View.通常您不会将 LineSeries 直接添加到 PlotView,而是添加到 PlotModel,然后绑定到 Plot View。
The C# code could look like this: 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;
The binding to Plot1 can of course also be done in XAML.与 Plot1 的绑定当然也可以在 XAML 中完成。 If your DataContext provides the PlotModel via a property 'MyModel', it would look like this:如果您的 DataContext 通过属性“MyModel”提供 PlotModel,它将如下所示:
<oxyplot:PlotView Model="{Binding MyModel}"></oxyplot:PlotView>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.