Add function use?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
coldwind
Newbie
Newbie
Posts: 41
Joined: Tue Dec 27, 2022 12:00 am

Add function use?

Post by coldwind » Tue Jan 17, 2023 4:51 am

hello:
i can see these code in InitializeComponent function which is generate automaticlly.

Code: Select all

this.bar1.XValues.DataMember = "X";
this.bar1.YValues.DataMember = "Bar";
i want to use code :

Code: Select all

Add(new {X=1,Bar=10.22});
Add(new {X=2,Bar=15.65});
to show chart .but it's nothing.
class Student {
string name;
int age;
//int weight;
}
so when i want to show my Student class data to chart , which set x axis is "name", set y axis is "age", how i need to do?
I want to code with these style:
this.bar1.XValues.DataMember="name";
this.bar1.XValues.DataMember="age";
....
this.tChart1[0].Add(new Student ('TOM',10));
this.tChart1[0].Add(new Student ('Lily',10));
this.tChart1[0].Add(new Student ('Jack',16));
...

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

Re: Add function use?

Post by Christopher » Tue Jan 17, 2023 11:19 am

Hello,

yes, you can use the IList overload of the Add function to do this, e.g.

Code: Select all

    private void InitializeChart()
    {
      var bar = new Bar(tChart1.Chart);

      var list = new List<Student>
      {
        new Student { Age = 10, Name = "Tom" },
        new Student { Age = 10, Name = "Lily" },
        new Student { Age = 16, Name = "Jack" }
      };


      bar.YValues.DataMember = "Age";
      bar.LabelMember = "Name";

      bar.Add(list as IList);
    }
Which gives me:
Screenshot from 2023-01-17 12-18-24.png
Screenshot from 2023-01-17 12-18-24.png (25.68 KiB) Viewed 6574 times
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

coldwind
Newbie
Newbie
Posts: 41
Joined: Tue Dec 27, 2022 12:00 am

Re: Add function use?

Post by coldwind » Thu Jan 19, 2023 6:30 am

Think you.
But i hope the Mark can custom.
e.g. set the format is

Code: Select all

$"{Name} is {Age}"
so the chart show like :
微信图片_20230119141525.png
微信图片_20230119141525.png (24.94 KiB) Viewed 6541 times

And I hope the mouse hover the Specified bar ,then the Mark will show like above.When the mouse leave the Specified bar ,the Mark will hide.

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

Re: Add function use?

Post by Christopher » Thu Jan 19, 2023 9:20 am

Hello,

yes, you can achieve this with code such as the following:

Code: Select all

    private void InitializeChart()
    {

      var bar = new Bar(tChart1.Chart);
      var markstip = new MarksTip(tChart1.Chart);

      var list = new List<Student>
      {
        new Student { Age = 10, Name = "Tom" },
        new Student { Age = 10, Name = "Lily" },
        new Student { Age = 16, Name = "Jack" }
      };

      void Bar_GetSeriesMark(Series Series, GetSeriesMarkEventArgs e)
      {
        e.MarkText = $"{list[e.ValueIndex].Name} is {list[e.ValueIndex].Age}";    
      }


      bar.YValues.DataMember = "Age";
      bar.LabelMember = "Name";

      bar.Add(list as IList);

      bar.GetSeriesMark += Bar_GetSeriesMark;
    }
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