charts - 对于此 Fsharp Charting Livechart 示例,为什么未设置引用?

标签 charts f#

open System
open System.Windows

open FSharp.Charting
open FSharp.Charting.ChartTypes

[<STAThread>]
do
    let win = Window(Title="Chart")

    let data = [|for i=1 to 10 do yield (i, i*i)|]

    let e = Event<_>()
    let ev = e.Publish

    let chart = LiveChart.Line (ev) |> ChartControl
    let host = new Forms.Integration.WindowsFormsHost(Child=chart)
    win.Content <- host

    e.Trigger data // Throws an error here

    Application().Run(win) |> ignore

我试图弄清楚 F# Charting 的 Livecharts 是如何工作的,但大多数示例都使用计时器或其他一些复杂的东西。上面是我能做到的最简单的,但由于某种原因,当我触发事件时,我不断收到 Object reference not set to an instance of an object. 异常。

知道为什么会发生这种情况吗?

编辑:这是跟踪。我必须删除上面示例中的捕获才能获取转储。

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at FSharp.Charting.NotifySeq.IObservable-1-ObserveOn@225-1.System-IObserver`1-OnNext(T value) in c:\GitHub\FSharp.Charting\src\FSharp.Charting.fs:line 226
   at <StartupCode$FSharp-Core><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ba5afcefdeee5ffa5e3cbbabcbfa6baa5c2e5fde4e0ee" rel="noreferrer noopener nofollow">[email protected]</a>(Object sender, T args)
   at Microsoft.FSharp.Control.FSharpEvent`1.Trigger(T arg)
   at <StartupCode$Charts>.$Program.main@() in C:\Users\Marko\Documents\Visual Studio 2015\Projects\Poker Experiments\Charts\Program.fs:line 20

最佳答案

查看FSCharting source code ,订阅时似乎没有事件的同步上下文。

您应该在窗口初始化时创建图表,这将在创建 WPF 同步上下文的 Application.Run 之后发生。

关于charts - 对于此 Fsharp Charting Livechart 示例,为什么未设置引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38510278/

相关文章:

Excel/VBA : Adding a title to doughnut chart reduces size of doughnut

C# - 实时更新图表

reactjs - 当我在 Github "Error: "line 上部署我的 React 应用程序时出现此错误“不是注册 Controller 。”

asp.net-mvc-3 - 我应该在 MVC3 和 ASP.net 中尝试 F# 吗?

F# 中 ||> 和 |||> 管道运算符的性能影响

reporting-services - SSRS 2008 图表 - 数据字段聚合?

javascript - 使用 zingchart 加载 CSV 文件

f# - F# 中的 IEquatable,= 运算符性能和结构平等

types - 在 F# 中定义非零整数类型

f# - 在序列计算表达式中的 for 循环中产生