Home
Insert
Update snippet 'University enrollment (CZE vs. EU)'
Title
Description
Using World Bank type provider and FSharpChart to show average university enrollment in Czech Republic, European Union and OECD members.
Source code
// Reference type provider and FSharpChart #r @"WorldBank.TypeProvider.dll" #load @"FSharpChart.fsx" open Samples.Charting open System.Windows.Forms.DataVisualization.Charting open System.Drawing let dashGrid = Grid(LineColor = Color.Gainsboro, LineDashStyle = ChartDashStyle.Dash) /// Draws line chart from year-value pairs using specified label & color let lineChart (data:seq<int * float>) name color = ( FSharpChart.Line(Array.ofSeq data, Name=name) |> FSharpChart.WithSeries.Style(BorderWidth = 2, Color = color) ) :> ChartTypes.GenericChart /// Calculate average university enrollment for EU let avgEU = [ for c in WorldBank.Regions.``European Union`` do yield! c.``School enrollment, tertiary (% gross)`` ] |> Seq.groupBy fst |> Seq.map (fun (y, v) -> y, Seq.averageBy snd v) |> Array.ofSeq |> Array.sortBy fst /// Calculate average university enrollment for OECD let avgOECD = [ for c in WorldBank.Regions.``OECD members`` do yield! c.``School enrollment, tertiary (% gross)`` ] |> Seq.groupBy fst |> Seq.map (fun (y, v) -> y, Seq.averageBy snd v) |> Array.ofSeq |> Array.sortBy fst // Generate nice line chart combining CZ and EU enrollment FSharpChart.Combine [ yield lineChart avgEU "EU" Color.Blue yield lineChart avgOECD "OECD" Color.Goldenrod let cze = WorldBank.Countries.``Czech Republic`` yield lineChart cze.``School enrollment, tertiary (% gross)`` "CZ" Color.DarkRed ] |> FSharpChart.WithLegend(Docking = Docking.Left) |> FSharpChart.WithArea.AxisY(MajorGrid = dashGrid) |> FSharpChart.WithArea.AxisX(MajorGrid = dashGrid)
Tags
type provider
world bank
fsharpchart
charting
type provider
world bank
fsharpchart
charting
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update