Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My F# Chart Library doesn't work in a 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'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?

like image 349
Luke Xu Avatar asked Mar 03 '16 02:03

Luke Xu


People also ask

What is Fsecure?

F-Secure Corporation (formerly Data Fellows) is a global cyber security and privacy company with over 30 offices around the world and is headquartered in Helsinki, Finland.

Does F-Secure have VPN?

F‑Secure FREEDOME VPN is the best VPN service for safeguarding your privacy. F-Secure FREEDOME VPN has been made to protect your privacy on the net. It encrypts your traffic and conceals your actual IP address. In addition, it includes features which actively block trackers that follow you on the internet.

Is F-secure good antivirus?

Is F-Secure Antivirus Software Good? F-Secure antivirus software is good and did well in our rating. F-Secure provides browsing and safe banking protections, parental controls, and a unique Finder Android/iPhone smartphone locator function to its mid-range SAFE plan.

How can I check my f-secure license?

Log in to My F-Secure. On the My F-Secure page, you can view the details of your subscription (subscription period, remaining days left, and number of free licenses). For more subscription-related information, select Subscription in the top bar.


2 Answers

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
like image 126
yuyoyuppe Avatar answered Oct 12 '22 10:10

yuyoyuppe


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

like image 27
s952163 Avatar answered Oct 12 '22 11:10

s952163