문제

I've got a LineSeries where DataFieldX values are DateTime, visually its working great but after implementing OnClick for the chart I can't seem to convert the selected value back to DateTime:

        Plot plot = sender as Plot;
        var series = plot.GetSeriesFromPoint(new ScreenPoint(e.GetPosition(plot).X, e.GetPosition(plot).Y), 10);
        var result = series.GetNearestPoint(new ScreenPoint(e.GetPosition(plot).X, e.GetPosition(plot).Y), true);
        var data = result.DataPoint;
        DateTime dt = new DateTime();
        dt = dt.AddSeconds(data.X);

data.X is 41577.61596880656, and the time for the point in the chart is 31/10/2013 14:47. dt ends up being 01.01.0001 11:32:57

How can I successfully convert data.X back to DateTime?

도움이 되었습니까?

해결책

You need to add days, not seconds to the date December 31, 1899

DateTime dt = new DateTime(1899,12,31);
dt = dt.AddDays(data.X);

For some reason when I run this I'm off by 0.3 seconds. I'm assuming that is based off of the precision of the format the data is being stored in.

enter image description here

다른 팁

Doesn't DateTimeAxis.ToDateTime() perform the required conversion?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top