I have a list of objects:
List<MyClass> MyList = new List<MyClass>();
the MyClass contains Properties Dtm and LastPrice that are updated real-time
public class MyClass
{
int dtm;
double lastPrice = 0;
public int Dtm
{
get { return dtm; }
set { dtm = value; }
}
public double LastPrice
{
get { return lastPrice; }
set { lastPrice = value; }
}
}
I want now a chart lined to the list that updates automatically each time the properties change. Any idea on how to do it?
Thanks
For an overview of Binding Data to Series (Chart Controls) see here!
The easiest way to bind your
List<T>
to aChart
is simply to set the List asDataSource
and to set the X- and Y-Value members:As for updating the chart you use the DataBind method:
Now you have two options:
Either you know when the values change; then you can simply add the call after the changes.
But maybe you don't know just when those changes occur or there are many actors that all may change the list.
For this you can add the
DataBind
call right into the setter of the relevant property:For this to work the List must learn about the chart to keep updated. I have added a reference to the class already. So before adding/binding points we set a chart reference:
The reference can be
static
, as all List elements will update the same chart.