Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#load a package in F# interactive (FSharpChart.fsx)

Hi i'm a noob and asking this newbie question, please forgive me.

I've installed successfully FSharpChart in my local directory

...
Added package 'MSDN.FSharpChart.dll.0.60.0' to folder 'C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Expert in F\packages'
Added package 'MSDN.FSharpChart.dll.0.60.0' to 'packages.config'
Successfully installed 'MSDN.FSharpChart.dll 0.60.0' to Expert in F

now, if i do

#load "FSharpChart.fsx";;
  ^^^^^^^^^^^^^^^^^^^^^^^

stdin(4,1): error FS0078: Unable to find the file 'FSharpChart.fsx' in any of
 C:\Users\Fagui\AppData\Local\Temp

additional info: directory

inside this folder, i see a nupkg file, and a lib directory Inside the lib directory, there is a dll, and a pdf file, but i don't see any .fsx file.

basically, F# has installed the package in the active folder for the current project, and F#interactive is in another folder ?? bit strange ?

should i install another time the package ? or what is the way around it ?

thanks

UPDATE: i don't know why, but apparently when i installed the FSharpChart package, I only got the dll, no fsx file i managed to load it doing

#I @"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Expert in F"
#r @"packages\MSDN.FSharpChart.dll.0.60\lib\MSDN.FSharpChart.dll";;

unfortunately, typing the script in F# interactive

open MSDN.FSharp.Charting
let rnd = System.Random()
let rand() = rnd.NextDouble()
let randomPoints = [for i in 0 .. 1000 -> 10.0 * rand(), 10.0 * rand()]
randomPoints |> FSharpChart.Point;;

doesn't yield any chart, but just returns a list

val rnd : Random
val rand : unit -> float
val randomPoints : (float * float) list =
  [(9.765916457, 2.272289941); (0.8211438594, 1.625466995);
   ...
   (7.783786034, 7.572208311); (6.497914692, 3.66987128); ...]
val it : ChartTypes.PointChart

this may be due to the fact that the library is not supported anymore, and that i should use a newer library like Thomas Petricek indicated.

So, i did manage to install FSharp.Charting instead

let rnd = System.Random()
let rand() = rnd.NextDouble()
let randomPoints = [for i in 0 .. 1000 -> 10.0 * rand(), 10.0 * rand()]
randomPoints |> Chart.Point;;

and it did work

like image 817
Fagui Curtain Avatar asked Dec 07 '25 10:12

Fagui Curtain


1 Answers

There is a newer version of the FSharpChart.fsx library which is called F# Charting, so first of all, I would recommend using this newer library instead (the API is quite similar, but F# Charting has a number of improvements).

The documentation for F# Charting also has a detailed page on referencing the library.

Typically, when you reference the library using NuGet, you'll need to specify relative reference:

// On Mac OSX use packages/FSharp.Charting.Gtk.0.90.13/FSharp.Charting.Gtk.fsx
#load "packages/FSharp.Charting.0.90.13/FSharp.Charting.fsx"

Where 0.90.13 is the version of the library that you got from NuGet (you may need to check the folder name - the path references in #load are relative to the place where your script lives).

like image 200
Tomas Petricek Avatar answered Dec 11 '25 09:12

Tomas Petricek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!