I have a list created from a linq query that contains 2 columns of data.
var result = root.Descendants().Elements("sensor")
.Where(el => (string)el.Attribute("name") == "Sensor1")
.Elements("evt")
.Select(el => new { t1 = el.Attribute("time").Value,
v1 = el.Attribute("val").Value })
.ToList()
I'm trying to use the chart control datasource to use that list, but when I call the bind method I receive this error:
System.ArgumentException was unhandled HResult=-2147024809
Message=Series data points do not support values of type <>f__AnonymousType0`2[System.Double,System.Decimal] only values of these types can be used: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort.
//result is a generic list defined as var result = root.Descendants()
chart1.DataSource = result;
chart1.DataBind(); // This is line that causes the exception.
Regards.
Yes it is possible, but not by binding the list to the
Chart
itself.There are several quite different methods to do Chart Databinding, all with different sets of pros and cons..
I suggest using the
Series.Points.DataBindXY
orSeries.Points.DataBind
methods.Here is an example:
Now create a generic list from it:
Now this works:
or also this:
In your case you would write maybe this:
Note that a
Chart
typically can only display pairs of values whereas aDGV
can create as many columns as theDataSource
has. SoChart
needs a little help in finding the x- and y-values..