非阻塞的图表.显示在fsharp . chart



使用FSharp。从.fs程序中绘制图表,当显示绘图时,它会阻止程序其余部分的执行。有没有一种方法可以生成非阻塞图表?例:我希望下面两段都显示在不同的窗口中,并让程序的其余部分执行。

Chart.Line(Series1) |> Chart.Show // Chart 1
// do some work
Chart.Line(Series2) |> Chart.Show // display this in a second window
// continue executing the rest while the above windows are still open.

您能提供更多关于如何调用Chart.Line的细节吗?例如,在REPL中,通过FSLab,在winforms中,在wpf?

在fsx文件中工作时,以下内容不会阻止我。另一种方法是将其封装在异步块中,这在执行长时间运行的计算或访问数据库时非常有用。

#load @"....FSLABpackagesFsLabFsLab.fsx"
open Deedle
open FSharp.Charting
open System
let rnd = System.Random()
let xs = List.init 100 (fun _ -> rnd.NextDouble() - 0.5)
let xs' =  List.init 100 (fun _ -> rnd.NextDouble() - 0.5)
Chart.Line(xs) // |> Chart.Show 
Chart.Line(xs') //|> Chart.Show

添加:

async {Chart.Line(xs)  |> Chart.Show } |> Async.Start 
async {Chart.Line(xs') |> Chart.Show } |> Async.Start

MS Docs和f# Fun&Profit

编制的例子:

open System
open FSharp.Charting
open System.Threading
open System.Threading.Tasks
open System.Drawing
open FSharp.Charting
open FSharp.Charting.ChartTypes

[<STAThread>]
[<EntryPoint>]
let main argv = 
    let rnd = System.Random()
    let xs = List.init 100 (fun _ -> rnd.NextDouble() - 0.5)
    let xs' =  List.init 100 (fun _ -> rnd.NextDouble() - 0.5)

    Chart.Line(xs)  |> Chart.Show 
    printfn "%A" "Chart 1"
    Chart.Line(xs') |> Chart.Show
    printfn "%A" "Chart 2"
    async {Chart.Line(xs)  |> Chart.Show } |> Async.Start 
    printfn "%A" "Chart 3"
    async {Chart.Line(xs') |> Chart.Show } |> Async.Start
    printfn "%A" "Chart 4"
    Console.Read() |> ignore
    printfn "%A" argv
    0 // return an integer exit code

相关内容

  • 没有找到相关文章

最新更新