使用 FSharp.Charting 获取 ArgumentNullException
Getting ArgumentNullException with FSharp.Charting
我正在尝试使用 FSharp.Charting 显示一个简单的图表。从 NuGet 中提取版本 0.90.14。
我 运行 在 Linux (Linux Mint) 上 Mono.Complete 包。
我的代码是:
#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: 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 FSharp.Charting.ChartTypes+layoutSubCharts@798-1.Invoke (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
成功了:
#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
需要这些步骤才能得到它运行:
- 将以 .fs 结尾的文件更改为 .fsx
- 使用FSharp.Charting.Gtk.fsx而不是FSharp.Charting.fsx.
- 允许本地主机连接到 X 服务器:xhost +localhost
- 运行 通过 fsharpi 的脚本而不是从 monodevelop 启动它:fsharpi Program.fsx
引用 (#r ...) 是在编译器抱怨缺少依赖项后添加的。
我必须同意@tomas-petricek。 FSharp.Charting 不建议在 Mono 上使用。这么多东西不起作用。例如 Live- 或 CombineCharts。
我正在尝试使用 FSharp.Charting 显示一个简单的图表。从 NuGet 中提取版本 0.90.14。
我 运行 在 Linux (Linux Mint) 上 Mono.Complete 包。
我的代码是:
#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: 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 FSharp.Charting.ChartTypes+layoutSubCharts@798-1.Invoke (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
成功了:
#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
需要这些步骤才能得到它运行:
- 将以 .fs 结尾的文件更改为 .fsx
- 使用FSharp.Charting.Gtk.fsx而不是FSharp.Charting.fsx.
- 允许本地主机连接到 X 服务器:xhost +localhost
- 运行 通过 fsharpi 的脚本而不是从 monodevelop 启动它:fsharpi Program.fsx
引用 (#r ...) 是在编译器抱怨缺少依赖项后添加的。
我必须同意@tomas-petricek。 FSharp.Charting 不建议在 Mono 上使用。这么多东西不起作用。例如 Live- 或 CombineCharts。