使用FSharp.Charting

时间:2016-05-08 12:02:52

标签: .net charts f# mono

我正在尝试使用FSharp.Charting显示一个简单的图表。从NuGet拉出0.90.14版本。

我使用Mono.Complete软件包在Linux(Linux Mint)上运行。

我的代码是:

#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) ]

在最后一行,我得到了:

  

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

  System.ArgumentNullException:值不能为null   参数名称:键


    在System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument参数)< 0x7f48488b7110 + 0x00021> in:0

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

    在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 visit,Microsoft.FSharp.Core.FSharpOption`1 targetParent,System.Object target)< 0x41cb58a0 + 0x0004d> in:0

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

    在FSharp.Charting.ChartTypes+layoutSubCharts@798-1 .Invoke(MS.F#。Core.FSharpOption`1 targetParent,System.Object target)< 0x41cb5850 + 0x0002b> in:0

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

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

    在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

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

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

    在FSharp.Charting.Chart.Line [a97,a98,a99](IEnumerable`1数据,FSharpOption`1名称,Microsoft.FSharp.Core.FSharpOption`1标题,FSharpOption`1标签,FSharpOption`1颜色,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&)     在System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object [] parameters,System.Globalization.CultureInfo culture)< 0x7f48489ab960 + 0x000a1> in:0

  因错误而停止

1 个答案:

答案 0 :(得分:0)

搞定了:

#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

需要这些步骤才能让它运行:

  1. 将文件从.fs更改为 .fsx
  2. 使用 FSharp.Charting.Gtk.fsx 而不是FSharp.Charting.fsx。
  3. 允许与X服务器建立本地主机连接: xhost + localhost
  4. 通过fsharpi运行脚本而不是从monodevelop启动脚本: fsharpi Program.fsx
  5. 在编译器抱怨缺少依赖项之后添加了引用(#r ...)。

    我必须同意@ tomas-petricek。 FSharp.Charting不建议在Mono上使用。这么多东西都没用。例如Live-或CombineCharts。