我刚开始学习F#,在理解如何使用F#图表中的记录序列时遇到了一些困难。
我有一个函数(ReturnTemp),它返回一系列TempData类型的记录。TempData由如下所示的记录类型定义
type TempData = {Date: System.DateTime; Year: int64 ; Location: string; Temperature: decimal}
我不清楚如何将此序列与Chart.Line一起使用,以便在x轴上绘制日期,在Y轴上绘制温度。
下面是一个使用TempData记录列表显示折线图的示例:
#r """..packagesFSharp.Charting.0.90.7libnet40FSharp.Charting.dll"""
#load """..packagesFSharp.Charting.0.90.7FSharp.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图表生成类似的图表。