2

I use code like the example below to do basic plotting of a list of values from F# Interactive. When plotting more points, the time taken to display increases dramatically. In the examples below, 10^4 points display in 4 seconds whereas 4.10^4 points take a patience-testing 53 seconds to display. Overall it's roughly as if the time to plot N points is in N^2.

The result is that I'll probably add an interpolation layer in front of this code, but

1) I wonder if someone who knows the workings of FSharpChart and Windows.Forms could explain what is causing this behaviour? (The data is bounded so one thing that seems to rule out is the display needing to adjust scale.)

2)Is there a simple remedy other than interpolating the data myself?

let plotl (f:float list) =
    let chart = FSharpChart.Line(f, Name = "")
            |> FSharpChart.WithSeries.Style(Color = System.Drawing.Color.Red, BorderWidth = 2)
    let form = new Form(Visible = true, TopMost = true, Width = 700, Height = 500)
    let ctl = new ChartControl(chart, Dock = DockStyle.Fill)
    form.Controls.Add(ctl)

let z1 = [for i in 1 .. 10000 do yield sin(float(i * i))]
let z2 = [for i in 1 .. 20000 do yield sin(float(i * i))]
plotl z1
plotl z2
imateapot
  • 141
  • 1
  • 1
  • 8
  • It is technically an O(n) algorithm, but modern processors have 4 distinct Ohs. The larger the dataset, the lower the odds that the data fits in the processor caches. It will really tank when it comes from the very slow RAM. Only collecting less data is a workaround, 40K points is far more than you need to draw an accurate chart. – Hans Passant Mar 22 '15 at 15:35

1 Answers1

4

First of all, FSharpChart is a name used in an older version of the library. The latest version is called F# Charting, comes with a new documentation and uses just Chart.

To answer your question, Chart.Line and Chart.Points are quite slow for large number of points. The library also has Chart.FastLine and Chart.FastPoints (which do not support as many features, but are faster). So, try getting the latest version of F# Charting and using the "Fast" version of the method.

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • I've just installed the F# Charting library, but my little plumbing to WIndows.Forms is now broken with the message: "The type 'FSharp.Charting.ChartTypes.GenericChart' is not compatible with the type 'MSDN.FSharp.Charting.ChartTypes.GenericChart'" . Is the solution to follow the instructions on the F# Charting website regarding WPF applications (here: http://fsharp.github.io/FSharp.Charting/UsingChartsInWPF.html) ? – imateapot Mar 23 '15 at 22:04
  • Ok one just has to be careful with the various references, see [this answer](http://stackoverflow.com/a/21139525/741956). Accepting your answer: with FastLIne I am able to (think that I) display a preposterous number of points in a short time. Thank you! – imateapot Mar 23 '15 at 22:18