本文介绍了oxyplot项目源数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用oxyplot

是否可以绑定数据表中的数据?

Is it possible to bind the data from a datatable ?

代码可以编译,但是仍然会出现异常:

The code compiles, but still gives an exception:

当前代码是:

 lineSeries1.ItemsSource = dt.DefaultView;

        lineSeries1.DataFieldY = "PartValues";
        lineSeries1.DataFieldX = "PartValuesId";
        grid.Children.Clear();
        MyModel.Series.Add(lineSeries1);
        Myview.Model = MyModel;
        grid.Children.Add(Myview);
        Grid.SetRow(Myview, 1);

数据表如下:

PartValuesId  PartIdKey  PartValues
6277           16          10
6273           16          12
6269           16          15
...

谢谢!

推荐答案

使它像这样工作:

   var results = from row in dt.AsEnumerable()
                 select new {
                       PartValuesId= row.Field<Int32>("PartValuesId"),
                       PartValues= row.Field<string>("PartValues")
                 };
   lineSeries1.ItemsSource = results;
   lineSeries1.DataFieldX = "PartValuesId";
   lineSeries1.DataFieldY = "PartValues";

这篇关于oxyplot项目源数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 16:49