Over on FSHUB, LethalLavaLand said,
Let me plot my values!
So the question is, how can I plot a data series in F# using built-in .NET 4.0 controls?
Since I've been working with the built-in Microsoft Charting Controls in .NET 4.0 lately (and loving every minute of it!), I thought I'd take a crack at answering my own question...
#r "System.Windows.Forms.DataVisualization"
open System.Windows.Forms
open System.Windows.Forms.DataVisualization.Charting
type LineChartForm( title, xs : float seq ) =
inherit Form( Text=title )
let chart = new Chart(Dock=DockStyle.Fill)
let area = new ChartArea(Name="Area1")
let series = new Series()
do series.ChartType <- SeriesChartType.Line
do xs |> Seq.iter (series.Points.Add >> ignore)
do series.ChartArea <- "Area1"
do chart.Series.Add( series )
do chart.ChartAreas.Add(area)
do base.Controls.Add( chart )
let main() =
let data = seq { for i in 1..1000 do yield sin(float i / 100.0) }
let f = new LineChartForm( "Sine", data )
f.Show()
main()
Don't forget, you don't have to do everything in F#.
You can roll up all your F# calculations into a library or class, and then use that in whatever "Front End" language you want:
E.g you could easily marry F# back end with WPF or Silverlight or C# WinForms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With