binding list<class> to mschart

Rhodan

Active member
Joined
Apr 7, 2015
Messages
41
Programming Experience
10+
I've done bindings to mschart before using datasets but now I want to use in-memory data without setting up databases etc.

What I've done is created a list<> of a simple class

C#:
       private class TrendEntry
        {
            public DateTime logTime;
            public Single room_Temp;
            public Single room_SP;
            public Single oat;
            public int heat_On;
        }

Created a list of that class and add it as the chart datasource then assign the fields

C#:
            private List<TrendEntry> TrendData = new List<TrendEntry>();

            Chart.DataSource = TrendData;

           Chart.Series[(int)SeriesID.ROOMTEMP].XValueMember = "logTime";
           Chart.Series[(int)SeriesID.ROOMTEMP].YValueMembers = "room_Temp";

create a new entry, add it to the list<> then databind
C#:
               TrendEntry trendPoint = new TrendEntry();
                trendPoint.logTime = DateTime.Now;
                trendPoint.room_Temp = room_Temp;
                trendPoint.room_SP = room_SP;
                trendPoint.oat = outside_Temp;
                trendPoint.heat_On = (room_HeatingDemand ? 1 : 0);
                TrendData.Add(trendPoint);
                Chart.DataBind();

When run I get an argument exception:

C#:
Series data points do not support values of type HVACSim.HVACSimFrm+TrendEntry only values of these types can be used: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort.

I'm guessing I'm overlooking something simple. Any ideas?
 
Figured it out.. You actually have to use getter/setter in the class. I use structs in other languages for this function but in MS you end up getting a copy of the struct rather than the struct itself so I went to using classes just like a struct. Works fine when you're manually setting/getting but I guess MSChart doesn't like it.
 
Back
Top Bottom