Page 1 of 1

yvalue datamember binding error

Posted: Mon May 08, 2023 7:49 am
by 20095116
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

Re: yvalue datamember binding error

Posted: Mon May 08, 2023 8:04 am
by Christopher
Hello,

could you please send us a minimal reproducible example with which we can see your problem here?

Re: yvalue datamember binding error

Posted: Wed May 10, 2023 8:51 am
by 20095116
Could you please provide me with your email address ? Unable to upload pictures

Re: yvalue datamember binding error

Posted: Wed May 10, 2023 9:13 am
by Christopher
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/

Re: yvalue datamember binding error

Posted: Thu May 11, 2023 3:06 am
by 20095116
I uploaded a note
Describes my problem
Can you receive it

Re: yvalue datamember binding error

Posted: Thu May 11, 2023 12:35 pm
by Christopher
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();
        }

Re: yvalue datamember binding error

Posted: Fri May 12, 2023 2:37 am
by 20095116

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

Re: yvalue datamember binding error

Posted: Fri May 12, 2023 7:45 am
by Christopher
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();
        }