Search code examples
chartsf#fsharpchartdotnetcharting

My F# Chart Library doesn't work in a project


open FSharp.Charting
open System

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    let x = Chart.Line [ for x in -100 .. 100 -> x, pown x 3]
    let y = Console.ReadKey();
    0 //return an integer exit code

Hello, I'm trying to play with the F# in PROJECT mode NOT a script. So far I have the code above as well as it told me to add a reference to System.Drawing which I also did.

I have 0 errors or warnings when I compile and it runs perfectly fine. The console screen appears but nothing else happens. The graph just doesn't show up or anything.

I HAVE tried this in the interactive window and it works perfectly fine there. Any ideas?


Solution

  • As @s952163 mentioned, you could wrap it to Winforms. However, ShowChart() already returns System.Windows.Form value. So, as long as you're pumping events with Application.Run(f), this code works fine too:

    [<EntryPoint>]
    let main argv = 
        printfn "%A" argv
        let f = (Chart.Line [ for x in -100 .. 100 -> x, pown x 3]).ShowChart()
        System.Windows.Forms.Application.Run(f)
        0