简体   繁体   English

在FSLAB中使用FSharp.Charting绘制Deedle系列并编译exe

[英]Plotting Deedle series with FSharp.Charting in FSLAB and compiled exe

When plotting a Deedle DataFrame or Series with FSharp.Charting FSLAB conveniently overloads the various Chart functions to work with Series directly. 当使用FSharp绘制Deedle DataFrame或Series时,Charting FSLAB可方便地重载各种Chart函数以直接与Series一起使用。 So I can do Series(x,y) |> Chart.Column for example. 所以我可以做Series(x,y) |> Chart.Column例如。 However when compiling Deedle and FSharp.Charting is referenced directly and the Series needs to be cast to Series.observations Series(x,y) |> Series.observations |> Chart.Column 但是,在编译Deedle和FSharp.Charting时,将直接引用该序列,并且必须将Series强制转换为Series.observations Series(x,y) |> Series.observations |> Chart.Column

Is there a way to avoid Series.observations ? 有办法避免Series.observations吗? Or do I need to define an extension method for all the different Charting functions? 还是我需要为所有不同的制图功能定义扩展方法? Which is what is suggested in Plotting Deedle frame 这是在绘制Deedle框架中建议的

Here's the code I used that works both in FSI or .exe: 这是我在FSI或.exe中均可使用的代码:

#if INTERACTIVE
#load @"..\..\FSLAB\packages\FsLab\FsLab.fsx"
#r @"Deedle"
#r @"Fsharp.Charting"
#endif

open System
open Deedle
open FSharp.Charting
open FSharp.Charting.ChartTypes
open System.Drawing
open System.Windows.Forms

   [<STAThread>]
   [<EntryPoint>]
   let main argv = 
        let x = ['a'..'j'] |> List.map string     
        let y = [1..10]
        let chart1 = Series(x,y) |> Series.observations |>  Chart.Column
        let myChartControl = new ChartControl(chart1, Dock=DockStyle.Fill)
        let form = new Form(Visible = true, TopMost = true, Width = 700, Height = 500)
        form.Controls.Add(myChartControl)
        do Application.Run(form) |> ignore

The convenient overloads are defined in the FsLab.fsx file that gets loaded when you reference FsLab from a script file. 方便的重载在FsLab.fsx文件中定义,当您从脚本文件引用FsLab时将加载该文件。 You can see them in the source code here . 您可以在此处的源代码中看到它们

We'd like to move those to a dll you could reference, but for now, the easiest option is to copy the helpers into a separate file in your project and just have a local copy. 我们希望将它们移动到您可以引用的dll ,但是目前,最简单的选择是将帮助程序复制到项目中的单独文件中,并仅具有本地副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM