yvalue datamember binding error

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
isetUser
Newbie
Newbie
Posts: 8
Joined: Thu Jan 19, 2023 12:00 am

yvalue datamember binding error

Post by isetUser » Mon May 08, 2023 7:49 am

Line line = new Line();
line.DataSource = dstable;
line.XValues.DataMember = dto.Xvalue;
line.Legend.Visible = false;
string str = dto.FileNameParament.ToString();
line.YValues.DataMember = str;

When I assign value to the Y-axis
An error will be reported
Indicating string errors
but YValues.DataMember is string
Please check the attached information

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

Re: yvalue datamember binding error

Post by Christopher » Mon May 08, 2023 8:04 am

Hello,

could you please send us a minimal reproducible example with which we can see your problem here?
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

isetUser
Newbie
Newbie
Posts: 8
Joined: Thu Jan 19, 2023 12:00 am

Re: yvalue datamember binding error

Post by isetUser » Wed May 10, 2023 8:51 am

Could you please provide me with your email address ? Unable to upload pictures

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

Re: yvalue datamember binding error

Post by Christopher » Wed May 10, 2023 9:13 am

isetUser wrote:
Wed May 10, 2023 8:51 am
Could you please provide me with your email address ? Unable to upload pictures
We would definitely prefer a minimal reproducible example to pictures, if possible.

You can upload the reproducible code to:
https://steema.cat/uploads/
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

isetUser
Newbie
Newbie
Posts: 8
Joined: Thu Jan 19, 2023 12:00 am

Re: yvalue datamember binding error

Post by isetUser » Thu May 11, 2023 3:06 am

I uploaded a note
Describes my problem
Can you receive it

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

Re: yvalue datamember binding error

Post by Christopher » Thu May 11, 2023 12:35 pm

Hello,

I think this maybe because you are trying to add a string to the YValues.DataMember when it expects a double value. To add a string value, please use the LabelMember, e.g.

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();

        }
        class Student
        {
            public string Name { get; set; }
            public double Value { get; set; }

            public Student(string name, double value)
            {
                Name = name;
                Value = value;
            }
        }

        private void InitializeChart()
        {
            var age = new Line(tChart1.Chart);
            age.YValues.DataMember = "Value";
            age.LabelMember = "Name";
            age.Title = "Age";

            void UseClass()
            {
                List<Student> list = new()
                {
                    new Student("A", 10),
                    new Student("B", 5),
                    new Student("C", 11),
                    new Student("D", 14)
                };

                age.Add(list as IList);
            }

            void UseTable() 
            {
                var table = new DataTable();
                table.Columns.Add(new DataColumn { DataType = typeof(string), ColumnName = "Name" });
                table.Columns.Add(new DataColumn { DataType = typeof(double), ColumnName = "Value" });
                var row1 = table.NewRow();
                row1["Name"] = "A";
                row1["Value"] = 10;
                table.Rows.Add(row1);
                var row2 = table.NewRow();
                row2["Name"] = "B";
                row2["Value"] = 5;
                table.Rows.Add(row2);
                var row3 = table.NewRow();
                row3["Name"] = "C";
                row3["Value"] = 11;
                table.Rows.Add(row3);
                var row4 = table.NewRow();
                row4["Name"] = "D";
                row4["Value"] = 14;
                table.Rows.Add(row4);

                age.DataSource = table;
                age.CheckDataSource();
            }
            //UseClass();
            UseTable();
        }
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

isetUser
Newbie
Newbie
Posts: 8
Joined: Thu Jan 19, 2023 12:00 am

Re: yvalue datamember binding error

Post by isetUser » Fri May 12, 2023 2:37 am

Code: Select all


private Line CreateLine(DataTable dstable, DPIDto dto, int i)
        {
            Line line = new Line();

            line.DataSource = dstable;
            line.LabelMember = dto.Xvalue;
             //line.XValues.DataMember = dto.Xvalue;
            line.Legend.Visible = false;
            string str = dto.FileNameParament[i].ToString();
            line.YValues.DataMember = str;
            line.Color = colors[i];

            line.Pointer.HorizSize = 1;
            line.Pointer.VertSize = 1;
            //line.ColorEachLine = true;
            //line.Legend.Text = dstable.TableName;
            line.Legend.BorderRound = 10;
            line.Pointer.Style = PointerStyles.Circle;
            line.Pointer.Visible = true;
            //line.Pointer.Color = Color.OrangeRed;
            //line.Pointer.SizeDouble = 1;
            line.XValues.DateTime = true;
            return line;
        }
now i use line.LabelMember show xaxis , error is gone, No error
but i used line.XValues.DataMember show xaxis ,still error
line.XValues.DataMember = dto.Xvalue; this dto.Xvalue data type is datetime ,xvalue is datetime
Why are errors reported

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

Re: yvalue datamember binding error

Post by Christopher » Fri May 12, 2023 7:45 am

Hello,

here's a working example using DateTime XValues:

Code: Select all

       public Form1()
        {
            InitializeComponent();
            InitializeChart();

        }
        class Student
        {
            public string Name { get; set; }
            public double Value { get; set; }
            public DateTime BirthDate { get; set; }

            public Student(string name, double value, DateTime birth)
            {
                Name = name;
                Value = value;
                BirthDate = birth;
            }
        }

        private void InitializeChart()
        {
            var age = new Line(tChart1.Chart);
            age.XValues.DateTime = true;
            age.XValues.DataMember = "BirthDate";
            age.YValues.DataMember = "Value";
            age.LabelMember = "Name";
            age.Title = "Children";

            void UseClass()
            {
                List<Student> list = new()
                {
                    new Student("A", 10, DateTime.Parse("1987-06-21")),
                    new Student("B", 5, DateTime.Parse("1992-12-03")),
                    new Student("C", 11, DateTime.Parse("1965-08-15")),
                    new Student("D", 14, DateTime.Parse("1979-02-09"))
                };

                age.Add(list as IList);
            }

            void UseTable() 
            {
                var table = new DataTable();
                table.Columns.Add(new DataColumn { DataType = typeof(string), ColumnName = "Name" });
                table.Columns.Add(new DataColumn { DataType = typeof(double), ColumnName = "Value" });
                table.Columns.Add(new DataColumn { DataType = typeof(DateTime), ColumnName = "BirthDate" });
                var row1 = table.NewRow();
                row1["Name"] = "A";
                row1["Value"] = 10;
                row1["BirthDate"] = DateTime.Parse("1987-06-21");
                table.Rows.Add(row1);
                var row2 = table.NewRow();
                row2["Name"] = "B";
                row2["Value"] = 5;
                row2["BirthDate"] = DateTime.Parse("1992-12-03");
                table.Rows.Add(row2);
                var row3 = table.NewRow();
                row3["Name"] = "C";
                row3["Value"] = 11;
                row3["BirthDate"] = DateTime.Parse("1965-08-15");
                table.Rows.Add(row3);
                var row4 = table.NewRow();
                row4["Name"] = "D";
                row4["Value"] = 14;
                row4["BirthDate"] = DateTime.Parse("1979-02-09");
                table.Rows.Add(row4);

                age.DataSource = table;
                age.CheckDataSource();
            }
            //UseClass();
            UseTable();
        }
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