Page 1 of 1

System.InvalidCastException:Invalid cast from Double to Date

Posted: Mon Feb 28, 2005 10:43 am
by 8122420
Help

I'm trying to display information about specific points a chart by using the SeriesClick event. I can display values for any series[x].YValues attribute but the minute I try to display the value of the XValues attribute I get the following error:

Invalid cast from Double to DateTime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Invalid cast from Double to DateTime.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Invalid cast from Double to DateTime.]
System.Double.System.IConvertible.ToDateTime(IFormatProvider provider) +72
System.Convert.ToDateTime(Double value) +51
NMBNTS03SPC._Default.WebChart1_ClickSeries(Object sender, Series s, Int32 valueIndex, EventArgs e) in c:\documents and settings\jholmes\vswebcache\uk501701o\nmbnts03spc\default.aspx.cs:159
Steema.TeeChart.Web.WebChart.Steema.TeeChart.IChart.DoClickSeries(Object sender, Series s, Int32 valueIndex, MouseEventArgs e) +36
Steema.TeeChart.Chart.DoMouseDown(Boolean IsDoubleClick, MouseEventArgs e) +358
Steema.TeeChart.Web.WebChart.CreatePictureFile(HtmlTextWriter writer) +568
Steema.TeeChart.Web.WebChart.Render(HtmlTextWriter output) +10
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +44
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +262
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +72
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1929

I have tried the following:

private void WebChart1_ClickSeries(object sender, Steema.TeeChart.Styles.Series s, int valueIndex, System.EventArgs e)
{
Steema.TeeChart.Chart tChart=((WebChart)sender).Chart;

lblProduct.Text = tChart.Series[4].YValues[valueIndex].ToString("0");
lblActual.Text = tChart.Series[0].YValues[valueIndex].ToString("0.00");
lblTarget.Text = tChart.Series[1].YValues[valueIndex].ToString("0.00");
lblUSL.Text = tChart.Series[2].YValues[valueIndex].ToString("0.00");
lblLSL.Text = tChart.Series[3].YValues[valueIndex].ToString("0.00");
lblTime.Text = Convert.ToDateTime(tChart.Series[4].XValues[valueIndex]).ToString();

}

Any assistance would be greatly appreciated.

Jim

Posted: Mon Feb 28, 2005 3:33 pm
by Chris
Hi Jim,

Instead of:

Code: Select all

lblTime.Text = Convert.ToDateTime(tChart.Series[4].XValues[valueIndex]).ToString();
Try:

Code: Select all

lblTime.Text = DateTime.FromOADate(tChart.Series[4].XValues[valueIndex]).ToLongDateString();

Posted: Mon Feb 28, 2005 4:29 pm
by 8122420
Many thanks Christopher,

Worked a treat.

Jim.