我刚刚开始使用F#并且在理解如何使用F#Charting的记录序列时遇到一些麻烦。
我有一个函数(ReturnTemp),它返回一个TempData类型的记录序列。 TempData由记录类型定义如下
type TempData = {Date: System.DateTime; Year: int64 ; Location: string; Temperature: decimal}
我不清楚如何使用Chart.Line的这个序列来绘制x轴上的Date和Y轴上的Temperature。
答案 0 :(得分:0)
以下是使用TempData记录列表显示折线图的示例:
#r """..\packages\FSharp.Charting.0.90.7\lib\net40\FSharp.Charting.dll"""
#load """..\packages\FSharp.Charting.0.90.7\FSharp.Charting.fsx"""
open FSharp.Charting
open System
type TempData = {
Date: System.DateTime
Year: int64
Location: string
Temperature: decimal
}
let data =
[
{Date = DateTime.Today.AddDays -4.; Year = 2014L; Location = "City X"; Temperature = 13M}
{Date = DateTime.Today.AddDays -3.; Year = 2014L; Location = "City X"; Temperature = 16M}
{Date = DateTime.Today.AddDays -2.; Year = 2014L; Location = "City X"; Temperature = 12M}
{Date = DateTime.Today.AddDays -1.; Year = 2014L; Location = "City X"; Temperature = 14M}
{Date = DateTime.Today; Year = 2014L; Location = "City X"; Temperature = 18M}
]
data
|> List.map (fun x -> x.Date, x.Temperature)
|> Chart.Line
您还可以使用FsPlot使用Highcharts或Google Charts生成类似的图表。