2
votes

I am trying to display a simple chart with FSharp.Charting. Pulled the version 0.90.14 from NuGet.

I am running on Linux (Linux Mint) with the Mono.Complete package.

My code is:

#I "../packages/FSharp.Charting.0.90.14"
#load "FSharp.Charting.fsx"

open FSharp.Charting
open System

// Drawing graph of a 'square' function
Chart.Line [ for x in 1.0 .. 100.0 -> (x, x ** 2.0) ]

At the last line, i am getting:

>
Chart.Line [ for x in 1.0 .. 100.0 -> (x, x ** 2.0) ];;

System.ArgumentNullException: Value cannot be null.
Parameter name: key

at System.ThrowHelper.ThrowArgumentNullException (ExceptionArgument argument) <0x7f48488b7110 + 0x00021> in :0

at System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (System.Collections.Generic.TKey key) <0x41cb5d70 + 0x00033> in :0

at System.Collections.Generic.Dictionary`2[TKey,TValue].ContainsKey (System.Collections.Generic.TKey key) <0x41cb5d30 + 0x00019> in :0

at FSharp.Charting.ChartTypes.layoutSubCharts@798 (SeriesChartType chartType, System.Collections.Generic.Dictionary`2 visited, Microsoft.FSharp.Core.FSharpOption`1 targetParent, System.Object target) <0x41cb58a0 + 0x0004d> in :0

at FSharp.Charting.ChartTypes.layoutSubCharts@798 (SeriesChartType chartType, System.Collections.Generic.Dictionary`2 visited, Microsoft.FSharp.Core.FSharpOption`1 targetParent, System.Object target) <0x41cb58a0 + 0x002e3> in :0

at [email protected] (MS.F#.Core.FSharpOption`1 targetParent, System.Object target) <0x41cb5850 + 0x0002b> in :0

at Microsoft.FSharp.Core.OptimizedClosures+Invoke@3252[T2,TResult,T1].Invoke (T2 u) <0x4190f660 + 0x00029> in :0

at FSharp.Charting.ChartTypes+applyPropertyDefaults@810-1[a].Invoke (a arg10) <0x41cb5820 + 0x00021> in :0

at Microsoft.FSharp.Core.FSharpFunc`2[T,TResult].InvokeFast[V] (Microsoft.FSharp.Core.FSharpFunc`2 func, Microsoft.FSharp.Core.T arg1, Microsoft.FSharp.Core.TResult arg2) <0x418dd260 + 0x000a5> in :0

at FSharp.Charting.ChartTypes.applyPropertyDefaults[a] (SeriesChartType chartType, FSharp.Charting.a target) <0x41cb5380 + 0x0016f> in :0

at FSharp.Charting.ChartTypes+GenericChart..ctor (SeriesChartType chartType) <0x41cb4c00 + 0x00173> in :0

at FSharp.Charting.Chart.Line[a97,a98,a99] (IEnumerable`1 data, FSharpOption`1 Name, Microsoft.FSharp.Core.FSharpOption`1 Title, FSharpOption`1 Labels, FSharpOption`1 Color, FSharpOption`1 XTitle, FSharpOption`1 YTitle) <0x41cab1d0 + 0x00057> in :0

at .$FSI_0004.main@ () <0x41ca9840 + 0x00073> in :0

at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x7f48489ab960 + 0x000a1> in :0

Stopped due to error

1
Works fine on vs2015 - Ringil
This is not really an answer, but F# Charting is not particularly mature on Mac/Linux. I've been recommending people to use XPlot instead: tahahachana.github.io/XPlot - Tomas Petricek

1 Answers

0
votes

Got it working:

#I "/usr/lib/cli/gtk-sharp-2.0/"
#I "/usr/lib/cli/gdk-sharp-2.0/"
#I "/usr/lib/cli/atk-sharp-2.0/"
#I "/usr/lib/cli/glib-sharp-2.0/"
#I "bin/Debug/"

#r "gtk-sharp.dll"
#r "gdk-sharp.dll"
#r "atk-sharp.dll"
#r "glib-sharp.dll"
#r "FSharp.Charting.Gtk.dll"

#load "../packages/FSharp.Charting.Gtk.0.90.14/FSharp.Charting.Gtk.fsx"

open FSharp.Charting
open System
open System.Threading


let runApp = async{
    Chart.Line([ for x in 0 .. 10 -> x, x*x ]).ShowChart()
    Gtk.Application.Run()
    }

let runMain  = async{

    printfn "Starting application"
    let! app = Async.StartChild runApp

    printfn "Press any key to exit..."
    let n = Console.ReadKey()
    Gtk.Application.Quit()
    printfn "Bye..."
    }

// run the whole workflow
Async.RunSynchronously runMain  

//Run script by:
//1. xhost +localhost
//2. fsharpi Program.fsx

These steps were needed to got it running:

  1. Change file ending from .fs to .fsx
  2. Use FSharp.Charting.Gtk.fsx rather than FSharp.Charting.fsx.
  3. Allowing localhost connections to the X server: xhost +localhost
  4. Running the script via fsharpi rather than starting it from monodevelop: fsharpi Program.fsx

The references (#r ...) were added after the compiler complained of missing dependencies.

I have to agree to @tomas-petricek. FSharp.Charting is not advisable to use on Mono. So much stuff is not working. For example Live- or CombineCharts.