My F # chart library is not working in the project

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 

Hello, I am trying to play with F # in PROJECT mode NOT a script. So far I have the code above, and also he told me to add a link to System.Drawing, which I also did.

I have 0 errors or warnings when compiling and it works fine. A console screen will appear, but nothing else will happen. The graph just does not appear or something else.

I tried this in an interactive window and there it works great. Any ideas?

+6
source share
2 answers

As mentioned in @ s952163, you can port it to Winforms. However, ShowChart() already returns the value of System.Windows.Form . So, while you are pumping events using Application.Run(f) , this code also works fine:

 [<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 
+6
source

You should just wrap it in Winforms. Take a look: How to display the FSharp.Charting chart in an existing form?

The example is very simple:

 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 

Refer to System.Drawing, System.Windows.Forms, System.Windows.Forms.DataVisualization

+4
source

All Articles