9
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'm trying to play with the F# in PROJECT mode NOT a script. So far I have the code above as well as it told me to add a reference to System.Drawing which I also did.

I have 0 errors or warnings when I compile and it runs perfectly fine. The console screen appears but nothing else happens. The graph just doesn't show up or anything.

I HAVE tried this in the interactive window and it works perfectly fine there. Any ideas?

Luke Xu
  • 2,302
  • 3
  • 19
  • 43

2 Answers2

9

As @s952163 mentioned, you could wrap it to Winforms. However, ShowChart() already returns System.Windows.Form value. So, as long as you're pumping events with Application.Run(f), this code works fine too:

[<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
yuyoyuppe
  • 1,582
  • 2
  • 20
  • 33
4

You should just wrap it in Winforms. Please see: How to display an FSharp.Charting graph in an existing form?

A very barebones example:

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

Please reference System.Drawing, System.Windows.Forms, System.Windows.Forms.DataVisualization

Community
  • 1
  • 1
s952163
  • 6,276
  • 4
  • 23
  • 47