F# Make Bar Chart with Winforms DataVisualization

2019-07-20 07:31发布

问题:

I want to make a bar Chart with Winforms and F#. I have seen many other C# examples making a chart with System.Windows.Forms.DataVisualization.Charting although when i try to open that library then it says then namespace is not defined.

Something as simple as this let chart = new Chart() doesn't work due to the namespace of the library not being defined i take it. Though I have seen people do this in C#. What is the correct way for F#?

Can someone be so kind to show me how to make a chart in F# and point me in the right direction of a bar Chart?

回答1:

You will need to reference the correct assembly then you can open the namespace (equivalent of C# using) like this:

open System.Windows.Forms.DataVisualization.Charting

However, before you go down this route, I would strongly recommend you use FSharp.Charting, which is a wrapper arround DataVisualization.Charting and much easier to work with in F#.

Here is a snippet using DataVisualization.Charting

Here is an example of using F# Charting