fslaborg / FSharp.Charting

Charting library suitable for interactive F# scripting
http://fslab.org/FSharp.Charting/
Other
215 stars 67 forks source link

LiveChart throws exception (despite working ostensibly ok) #65

Open anton-pt opened 9 years ago

anton-pt commented 9 years ago

When run, the following code silently throws an exception at the line:

let chartControl = new ChartControl(chart),

despite ostensibly running just fine. The message in the output window is: "A first chance exception of type 'System.InvalidOperationException' occurred in FSharp.Core.dll"

open System
open System.Drawing
open System.Reactive.Linq
open System.Threading
open System.Windows.Forms
open FSharp.Charting
open FSharp.Charting.ChartTypes

// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.

[<EntryPoint>]
let main argv = 
    printfn "%A" argv

    let form = new Form()
    form.Size <- new Size(800, 600)

    let step =
        let gen = new Random()
        (fun () -> 2.0 * (gen.NextDouble() - 0.5))

    let randomWalk =
        Observable
            .Interval(TimeSpan.FromMilliseconds 200.0)
            .ObserveOn SynchronizationContext.Current 
        |> Observable.scan (fun (x, y) _ -> (x + 1.0, y + step())) (0.0, 0.0)

    let chart = LiveChart.FastLineIncremental randomWalk

    let chartControl = new ChartControl(chart)
    chartControl.Dock <- DockStyle.Fill

    form.Controls.Add chartControl

    Application.Run(form)
    0 // return an integer exit code

Am I doing something that I shouldn't be doing?

dsyme commented 9 years ago

This may be relevant: https://github.com/fslaborg/FSharp.Charting/issues/33#issuecomment-32493386