LChart: displaying charts in F# – Part I
Luca -
☕ 2 min. read
I want to use F# as a exploratory data analysis language (like R). But I don’t know how to get the same nice graphic capabilities. So I decided to create them. Here is a library to draw charts in F#. It steals ideas from this book and this R package. It is nothing more than a wrapper on top of the Microsoft Chart Controls to give it a more ‘exploratory’ one line calling syntax. It is also rough work in progress: I don’t wrap all the chart types and there are bugs in the ones I wrap. Also the architecture is all wrong (more on this in another post). But it’s a start and it kind of works. Attached the full code.
I will continue this series in my new blog at wordpress: http://lucabolognese.wordpress.com/. The reason I need a new blog will be explained in an upcoming post.
Part II is now here.
Ok, let’s start. How do I draw a chart?
let x = [1.;2.5;3.1;4.;4.8;6.0;7.5;8.;9.1;15.] let y = [1.6;2.1;1.4;4.;2.3;1.9;2.4;1.4;5.;2.9] lc.scatter(x, y) |> display
X and Y are just some make up data. lc is the name of a class (???) and scatter is a static method on it. scatter doesn’t display the chart, it just produces a an object that represents the chart. Display displays the chart. The reason for using the bizarre lc static class is that I want it to be short so that it is easy to type in the fsi.exe. At the same time it needs to support optional parameters (which are not supported on top level functions in F#).
You get a window with this chart on it. You can press CTRL+C to copy it (as I did to post it here).
You might want to customize the chart a bit by passing some of these famous optional parameters:
lc.scatter(x = x, y = y, markerSize = 10, markerStyle = MarkerStyle.Diamond, xname = "Players", yname = "Ratings", title = "Players' Ratings") |> display
Or you might want to print different types of charts:
lc.line(y = y, markerSize = 10, markerStyle = MarkerStyle.Diamond, xname = "Players", yname = "Ratings", title = "Players' Ratings", isValueShownAsLabel = true, color = Color.Red) |> display
lc.spline(x = x, y = y, markerSize = 10, markerStyle = MarkerStyle.Diamond, xname = "Players", yname = "Ratings", title = "Players' Ratings", isValueShownAsLabel = true, color = Color.Red) |> display
lc.stepline(x = x, y = y, markerSize = 10, markerStyle = MarkerStyle.Diamond, xname = "Players", yname = "Ratings", title = "Players' Ratings", isValueShownAsLabel = true, color = Color.Red) |> display
lc.bar(y = y, xname = "Players", yname = "Ratings", title = "Players' Ratings", isValueShownAsLabel = true, drawingStyle = "Emboss") |> display
lc.column(y = y, xname = "Players", yname = "Ratings", title = "Players' Ratings", isValueShownAsLabel = true, drawingStyle = "Cylinder") |> display
lc.boxplot(y = y, xname = "Players", yname = "Ratings", title = "Players' Ratings", color = Color.Blue, whiskerPercentile = 5, percentile = 30, showAverage = false, showMedian = false, showUnusualValues = true) |> display
Ok, the last one is weird. You probably want more than one boxplot in a chart. I’ll show you how to do that in the next post.
The next post will be on how to have more than one series on the same chart and more than one chart in the same windows. Something like the below:
0 Webmentions
These are webmentions via the IndieWeb and webmention.io.