Feature TF02013957

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Feature TF02013957

Post by rpt » Tue Aug 30, 2016 12:53 pm

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

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Feature TF02013957

Post by Christopher » Tue Aug 30, 2016 3:02 pm

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;
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply