FSharp.Charting: Live Animated Charts
Summary: This example shows a collection of LiveCharts, which update as data changes.
The input data comes from IObservable
(or IEvent
) sources.
The data can be created using F# AsyncSeq, Rx, F# Event combinators or F# Observable combinators.
The samples are not yet individually documented.
In this sample, some extra event combinators are used to generate reactive data.
The EventEx-0.1.fsx
file can be found
here.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
|
// On Mac OSX use FSharp.Charting.Gtk.fsx
#I "packages/FSharp.Charting"
#load "FSharp.Charting.fsx"
#load "EventEx-0.1.fsx"
#r "../../packages/FSharp.Control.AsyncSeq/lib/net45/FSharp.Control.AsyncSeq.dll"
open System
open System.Drawing
open FSharp.Charting
open FSharp.Control
|
The following code generates sample data - both as a list of values
and as an F# event (IObservable
) that can be passed to live charts:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
|
let timeSeriesData =
[ for x in 0 .. 99 ->
DateTime.Now.AddDays (float x),sin(float x / 10.0) ]
let rnd = new System.Random()
let rand() = rnd.NextDouble()
let data = [ for x in 0 .. 99 -> (x,x*x) ]
let data2 = [ for x in 0 .. 99 -> (x,sin(float x / 10.0)) ]
let data3 = [ for x in 0 .. 99 -> (x,cos(float x / 10.0)) ]
let incData = Event.clock 10 |> Event.map (fun x -> (x, x.Millisecond))
|
You can use Event.cycle
to create a simple live data source that
iterates over in-memory sequence, or you can use an event as follows:
1:
2:
3:
4:
5:
6:
7:
8:
|
// Cycle through two data sets of the same type
LiveChart.Line (Event.cycle 1000 [data2; data3])
LiveChart.LineIncremental(incData,Name="MouseMove")
.WithXAxis(Enabled=false).WithYAxis(Enabled=false)
LiveChart.FastLineIncremental(incData,Name="MouseMove")
.WithXAxis(Enabled=false).WithYAxis(Enabled=false)
|