Hi.
I Use database table as line series datasouce.
In this table exists Date Column(X) and Value Column(Y).
When the Value is DBNull I get error:"Object cannot be cast from DBNull to other types".
If I change X and Y to Value Column DataMember it don't happens.
What is the trouble with dateTime Column?
Steema.TeeChart.Styles.Line serLine = new Steema.TeeChart.Styles.Line();
tcrBase.Series.Add(serLine);
serLine.DataSource = dt;
serLine.XValues.DataMember=DateColumnName;
serLine.YValues.DataMember = valueColumnName;
Thanks,Sonia
DateTime XValues DB Column
Hi Sonia,
I've just test it here using the following code (with the latest available version) and does not give me any error. But I've noticed that it does not work as it should, the problem is that instead of one null value at the beginning of the series and one at the end there are two at the beginning. I've added this on our defect list and a fix for it will be considered to inclusion for the next emaintenance releases.
I've just test it here using the following code (with the latest available version) and does not give me any error. But I've noticed that it does not work as it should, the problem is that instead of one null value at the beginning of the series and one at the end there are two at the beginning. I've added this on our defect list and a fix for it will be considered to inclusion for the next emaintenance releases.
Code: Select all
Random r=new Random(10);
DataTable myTable = new DataTable("myTable");
DataColumn colDate = new DataColumn("Date",Type.GetType("System.DateTime"));
DataColumn colValue = new DataColumn("Value",Type.GetType("System.Int32"));
myTable.Columns.Add(colDate);
myTable.Columns.Add(colValue);
// Add five items.
DataRow NewRow;
NewRow = myTable.NewRow();
NewRow["Date"] = DBNull.Value;
NewRow["Value"] = DBNull.Value;
myTable.Rows.Add(NewRow);
for(int i = 0; i <5; i++)
{
NewRow = myTable.NewRow();
NewRow["Date"] = System.DateTime.Today.AddDays(i);
NewRow["Value"] = r.Next(10);
myTable.Rows.Add(NewRow);
}
NewRow = myTable.NewRow();
NewRow["Date"] = System.DateTime.Today.AddDays(7);
NewRow["Value"] = DBNull.Value;
myTable.Rows.Add(NewRow);
DataView firstView = new DataView(myTable);
tChart1.Series[0].YValues.DataMember=colValue.ToString();
tChart1.Series[0].XValues.DateTime = true;
tChart1.Series[0].XValues.DataMember=colDate.ToString();
tChart1.Series[0].DataSource=firstView;
Pep Jorge
http://support.steema.com
http://support.steema.com