Remembering Thoughts
  Twitter GitHub RSS

LinqPad and F# Charting

Import these references

image

Sample script

/// Must be run in LINQPAD 4 - gives missing method exception in linqpad 5
let dc = new TypedDataContext()
open System
open System.IO
open XPlot.GoogleCharts
open XPlot.Plotly
open XPlot.GoogleCharts.Data
open XPlot.GoogleCharts.Configuration
open XPlot.Plotly.HTML
let getAge (d : DateTime) =
let result = DateTime.Today.Year - d.Year
// printfn "%i" result
result
let query = query
{
for row in dc.Clients do
select row
//take 1000
}
let ages = query
|> Seq.map (fun row -> getAge(row.DateOfBirth.GetValueOrDefault(DateTime.Today)))
|> Seq.filter (fun x -> x > 0)
|> Seq.filter (fun x -> x < 100)
|> Seq.map(fun x-> "Client ages" , x)
//ages.Count() |> Dump
Chart.Histogram ages
|> Chart.WithOptions (Options(title = "Client Ages"))
|> Chart.WithLabel "Total"
|> Chart.Show
|> ignore

Graph

  image


Published:

Share on Twitter