Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving DateTime x-axis value from Chart control

Tags:

c#

asp.net

I have a chart control with a data in it. The x-axis data is of DateTime and the Y-axis is an integer. I'm trying to pull the data out of the graph and export it to excel, but the DateTime values aren't coming out in a way I can understand them or figure out how to decode them.

Example values are as such:

The graph begins at 4/30/2012 and goes to 8/13/2012.

The values show:

{X=41030, Y=16991}
{X=41031, Y=34363}
{X=41032, Y=26744}
{X=41033, Y=28180}
{X=41034, Y=17478}

...intermediate values

{X=41134, Y=1785}

I set the chart x-axis type to date time with

RestartBooksAttempts.Series["Attempts"].XValueType = ChartValueType.DateTime;
RestartBooksAttempts.Series["Books"].XValueType = ChartValueType.DateTime;

and I'm grabbing the values with:

Convert.ToDateTime(chart.Series[s.Name].Points[i].XValue)
double y = chart.Series[s.Name].Points[i].YValues[0];

obviously the x-points are not a DateTime convertable value, does anyone have any idea how to decode these values?

like image 453
tareqx3 Avatar asked Aug 14 '12 15:08

tareqx3


1 Answers

Ok, I found it out.

You have to use DateTime.FromOADate(double) to convert it back.

like image 196
tareqx3 Avatar answered Sep 28 '22 18:09

tareqx3