Page 1 of 1
Feature TF02013957
Posted: Tue Aug 30, 2016 12:53 pm
by 9642129
Is this feature available - discussed here -
http://teechart.net/support/viewtopic.php?f=4&t=9374
Feature : TF02013957 - Does Teechart support datasource as Generic List<T>?
I went to
http://bugs.teechart.net/ could not find the status
Re: Feature TF02013957
Posted: Tue Aug 30, 2016 3:02 pm
by Christopher
Hello,
Yes, List<T> can be used as a DataSource - first a small test class:
Code: Select all
public class Person
{
private string firstName;
private string lastName;
private DateTime dob;
private Color favorite;
private int height;
public Person(string first, string last, DateTime dob, Color favorite, int height)
{
this.firstName = first;
this.lastName = last;
this.dob = dob;
this.favorite = favorite;
this.height = height;
}
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public DateTime DateOfBirth
{
get { return dob; }
set { dob = value; }
}
public Color FavoriteColor
{
get { return favorite; }
set { favorite = value; }
}
public int Height
{
get { return height; }
set { height = value; }
}
}
which can be consumed like this:
Code: Select all
private Steema.TeeChart.Styles.Bar bar;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Series.Add(bar = new Steema.TeeChart.Styles.Bar());
bar.XValues.DataMember = "DateOfBirth";
bar.YValues.DataMember = "Height";
bar.LabelMember = "LastName";
bar.ColorMember = "FavoriteColor";
List<Person> list = new List<Person>();
list.Add(new Person("Willa", "Cather", DateTime.Parse("22/09/1941"), Color.Red, 171));
list.Add(new Person("Isak", "Dinesen", DateTime.Parse("01/07/1964"), Color.Green, 189));
list.Add(new Person("Victor", "Hugo", DateTime.Parse("30/03/1987"), Color.Blue, 196));
list.Add(new Person("Jules", "Verne", DateTime.Parse("14/10/1995"), Color.Orange, 175));
bar.DataSource = list;
}