LChart: displaying charts in F# – Part I

-

I want to use F# as a ex­ploratory data analy­sis lan­guage (like R). But I don’t know how to get the same nice graphic ca­pa­bil­i­ties. So I de­cided to cre­ate them. Here is a li­brary to draw charts in F#. It steals ideas from this book and this R pack­age. It is noth­ing more than a wrap­per on top of the Microsoft Chart Controls to give it a more exploratory’ one line call­ing syn­tax. 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 ar­chi­tec­ture is all wrong (more on this in an­other post). But it’s a start and it kind of works. Attached the full code.

I will con­tinue this se­ries in my new blog at word­press: http://​lu­cabolog­nese.word­press.com/. The rea­son I need a new blog will be ex­plained in an up­com­ing 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 scat­ter is a sta­tic method on it. scat­ter does­n’t dis­play the chart, it just pro­duces a an ob­ject that rep­re­sents the chart. Display dis­plays the chart. The rea­son for us­ing the bizarre lc sta­tic 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 sup­port op­tional pa­ra­me­ters (which are not sup­ported on top level func­tions in F#).

You get a win­dow with this chart on it. You can press CTRL+C to copy it (as I did to post it here).

image

You might want to cus­tomize the chart a bit by pass­ing some of these fa­mous op­tional pa­ra­me­ters:

lc.scatter(x = x, y = y, markerSize = 10, markerStyle = MarkerStyle.Diamond,
    xname = "Players", yname = "Ratings", title = "Players' Ratings")  |> display     

image

Or you might want to print dif­fer­ent 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       

image

lc.spline(x = x, y = y, markerSize = 10, markerStyle = MarkerStyle.Diamond, xname = "Players", yname = "Ratings",
    title = "Players' Ratings", isValueShownAsLabel = true, color = Color.Red) |> display 

image

lc.stepline(x = x, y = y, markerSize = 10, markerStyle = MarkerStyle.Diamond, xname = "Players", yname = "Ratings",
    title = "Players' Ratings", isValueShownAsLabel = true, color = Color.Red) |> display

image

lc.bar(y = y, xname = "Players", yname = "Ratings", title = "Players' Ratings", isValueShownAsLabel = true,
    drawingStyle = "Emboss") |> display      

image

 

lc.column(y = y, xname = "Players", yname = "Ratings", title = "Players' Ratings",
    isValueShownAsLabel = true, drawingStyle = "Cylinder") |> display   

image

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    

image

Ok, the last one is weird. You prob­a­bly want more than one box­plot 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 se­ries on the same chart and more than one chart in the same win­dows. Something like the be­low:

image

ChartPlotter.fsx

Tags