8
open FSharp.Charting
open System

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    let x = Chart.Line [ for x in -100 .. 100 -> x, pown x 3]
    let y = Console.ReadKey();
    0 //return an integer exit code

您好,我正在尝试在PROJECT模式下使用 F# 而不是脚本。到目前为止,我有上面的代码,它告诉我添加对 System.Drawing 的引用,我也这样做了。

编译时出现 0 个错误或警告,并且运行良好。控制台屏幕出现,但没有其他反应。该图只是没有显示或任何东西。

我已经在交互式窗口中尝试过这个,它在那里工作得很好。有任何想法吗?

4

2 回答 2

9

正如@s952163 提到的,您可以将其包装到 Winforms。但是,ShowChart()已经返回System.Windows.Form值。因此,只要您使用 抽事件Application.Run(f),此代码也可以正常工作:

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    let f = (Chart.Line [ for x in -100 .. 100 -> x, pown x 3]).ShowChart()
    System.Windows.Forms.Application.Run(f)
    0
于 2016-03-03T03:42:25.210 回答
4

您应该将其包装在 Winforms 中。请参阅:如何在现有表单中显示 FSharp.Charting 图?

一个非常简单的例子:

open FSharp.Charting
open System
open System.Windows.Forms

[<STAThread>]
[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    let chart = Chart.Line [ for x in -100 .. 100 -> x, pown x 3]
    let f1 = new Form(Visible = true, TopMost = true, Width = 700, Height = 500)
    f1.Controls.Add(new ChartTypes.ChartControl(chart, Dock = DockStyle.Fill))
    Application.Run(f1)
   0 // return an integer exit code

请参考 System.Drawing、System.Windows.Forms、System.Windows.Forms.DataVisualization

于 2016-03-03T03:40:07.023 回答