Search code examples
f#fsharpchart

Importing FSharp.Charting in .fs file fails


  1. Create a new FSharp Console project via VS2015
  2. Add FSharp.Data and FSharp.Charting nuget package.
  3. In Program.fs import both the packages

open FSharp.Charting open Fsharp.Data

After the import I am able to use functions provided in FSharp.Data package but not in FSharp.Charting.

NOTE: In case of script (.fsx) file, which created in the same project, I am able to use both after adding their reference.

I just wanted to to know if there are any steps i am missing for adding any reference in a .fs file. If yes then why does it work with respect to FSharp.Data package.


Solution

  • I think if you search SO you'll find a few examples of displaying charts with FSharp.Charting. It's not exactly clear what sort of error are you getting. Assuming you are on Windows this should work:

    open FSharp.Charting
    open System
    
    [<STAThread>]
    [<EntryPoint>]
    let main argv = 
        Chart.Line [ for x in 0 .. 10 -> x, x*x ] |> Chart.Show
        printfn "%A" argv
        0 // return an integer exit code
    

    You will need to add references to System.Windows.Forms, System.Windows.Forms.DataVisualization and System.Drawing.