tags:

views:

396

answers:

3

I feed a Microsoft Chart control with a IEnumerable of my own class ChartPoint

    public class ChartPoint
    {
        public double Xvalue { get; set; }
        public double Yvalue { get; set; }
        public string Url { get; set; }
        public string Tooltip { get; set; }
    }

then i tries to DataBind the IEnumerable< ChartPoint>:

serie.Points.DataBind(points, "Xvalue", "Yvalue", "Tooltip=Tooltip,Url=Url");

but i then hits a NotImplementedException on that row:

 System.Linq.Iterator`1.System.Collections.IEnumerator.Reset() +29
   System.Web.UI.DataVisualization.Charting.DataPointCollection.DataBind(IEnumerable dataSource, String xField, String yFields, String otherFields) +313

What am I doing wrong?

+1  A: 

Are you using iterator blocks (i.e. yield return)? The compiler won't generate a Reset method if you do generates a Reset method but the method throws a NotImplementedException.

Andrew Hare
Minor correction. It does generate a Reset (IEnumerator<T> requires it), it just throws a NotImplementedException
JaredPar
Very true - answer corrected!
Andrew Hare
+4  A: 

Are you using a C# iterator?

C# iterators do not implement the Reset function on the generated IEnumerator and will throw a NotImplementedException if it is called. It looks like the particular control requires that method to be present.

You will likely have to use a collection which supports Reset on it's iterator. The easiest way to achieve this is to use a List<T> to wrap your existing IEnumerable<T>

For example

List<ChartPoint> list = new List<ChartPoint>(points);
serie.Points.DataBind(list, "Xvalue", "Yvalue", "Tooltip=Tooltip,Url=Url");
JaredPar
Solved, thanks!
Carl Hörberg
+1 For a solution to the problem!
Andrew Hare
A: 

See my bug report on Connect here. Please vote for this and maybe MS will fix it in the next Chart release.