Reputation: 8280
I have a collection that is in format datetimeoffset - option int64. I would like to plot a line from this data.
I tried with with just piping my data to Chart.Line:
Chart.Line(data |> Seq.map (fun r -> r.time.DateTime, r.input.Value))
but i got following output.
Now I know my data doesn't look like this. At least I tried running:
data |> Array.map (fun r -> r.Timestamp.DateTime) |> Array.min
data |> Array.map (fun r -> r.Timestamp.DateTime) |> Array.max
And got
DateTime = 10/29/2014 6:30:15 PM
DateTime = 10/30/2014 6:00:15 PM
So I don't have any data near the beginning of the previous century.
When I plot by DateTime.Ticks instead of datetime data looks as it should be looking:
Any idea what is going on here?
Upvotes: 1
Views: 190
Reputation: 243096
Based on the screenshot, I suppose you're using the F# Charting library.
I did a quick test using the latest version and it seems to be handling DateTimeOffset
correctly as the key, but DateTime
incorrectly! Given the following setup:
#load "packages/FSharp.Charting.0.90.7/FSharp.Charting.fsx"
open FSharp.Charting
open System
The following works fine:
[ for i in 0 .. 100 do
yield DateTimeOffset(DateTime.Now.AddHours(float i)), int64 i ]
|> Chart.Line
But the following behaves similarly to your snippet:
[ for i in 0 .. 100 do
yield DateTime.Now.AddHours(float i), int64 i ]
|> Chart.Line
So the workaround for you should be to just return r.time
rather than getting DateTime
:
Chart.Line(data |> Seq.map (fun r -> r.time, r.input.Value))
This seems to be a bug! Please submit an issue on the project GitHub page.
EDIT Figured it out - there is a difference between how DateTime
and DateTimeOffset
behave.
Upvotes: 1