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
yvalue datamember binding error
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: yvalue datamember binding error
Hello,
could you please send us a minimal reproducible example with which we can see your problem here?
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 |
Re: yvalue datamember binding error
Could you please provide me with your email address ? Unable to upload pictures
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: yvalue datamember binding error
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 |
Re: yvalue datamember binding error
I uploaded a note
Describes my problem
Can you receive it
Describes my problem
Can you receive it
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: yvalue datamember binding error
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.
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 |
Re: yvalue datamember binding error
now i use line.LabelMember show xaxis , error is gone, No errorCode: 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; }
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
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: yvalue datamember binding error
Hello,
here's a working example using DateTime XValues:
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 |