Linq,DataVisualization和AsEnumerable [英] Linq, DataVisualization and AsEnumerable
问题描述
您好,我正在编写一个用于绘制大量数据图表的应用程序.我可以将某些图表用于DataVisualization.Charting Charts.
我尝试使用Points.DataBindXY方法将数据(存储在数据集中)绑定到Chart.Series.我想使用LinQ,所以我可以加入一些表运行时.
DatabindXY方法的x轴和y轴都需要IEnumerable.我认为使用LinQ会很容易.
为了进行测试,我制作了一个小应用程序,使用一个表"Organisations"定义一个数据集,其中包含两个字段:id和value.我想绘制一个图表,在x轴上有id,在y轴上有值.我尝试了以下代码:
Hello, I''m writing an application for charting a lot of data. I can use for some of the graphs the DataVisualization.Charting Charts.
I try to bind my data (which is stored in a dataset) to a Chart.Series with the Points.DataBindXY method. I want to use LinQ, so I can join some tables runtime.
The DatabindXY method needs a IEnumerable for both x- and y-axis. I thought that would be quite easy using LinQ.
For testing purposes, I made a small application, defining a dataset with one table, "Organisations", holding two fields: id and value. I want to draw a chart, having the id on the x-axis and the value on the y-axis. I tried the following code:
Dim chart1 As New Charting.Chart
chart1.Series.Add("org")
Dim orgs = ds.Tables("Organisations").AsEnumerable
chart1.Series("org").Points.DataBindXY(orgs.GetEnumerator, orgs.CopyToDataTable.Rows.Item(0), orgs.CopyToDataTable.Rows.GetEnumerator, orgs.CopyToDataTable.Rows.Item(1))
但是,这不起作用.我收到错误消息:无法将类型为"System.Data.DataRow"的对象转换为类型为"System.Collections.IEnumerable".
在互联网上,我找不到将图表绑定到LinQ查询的两个字段的方法.
请帮帮我!
Joris Bijvoets
However, this doesn''t work. I get the error: Unable to cast object of type ''System.Data.DataRow'' to type ''System.Collections.IEnumerable''.
On the internet I can''t find the way how to bind my chart to two fields of my LinQ-query.
Please, help me!
Joris Bijvoets
推荐答案
您可能想看看 http://www.hookedonlinq.com/LINQtoDatasets.ashx [ ^ ].
这篇关于Linq,DataVisualization和AsEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!