title: Is it possible to use or extend the FSharpChart library to create a line chart of a sliding window?
body: <p>I have been trying to figure out how to create a chart in F#, using the FSharpCharting library, which shows a sliding window of data. For example, I would like to be able to show all values for the past 3 minutes. Values older than that would fall off the chart, and be replaced as new values were observed.</p>
  
  <p>Based on my experiments, I don't think that the underlying Microsoft Chart Controls support this scenario. Does anyone know if it is possible to create this type of chart? Are there other alternatives that have this capability?</p>
  
  <p>Here is the 'experiment' that I tried. The task to update the values in the series produces an exception </p>
  
  <blockquote>
    <p>System.InvalidOperationException: Collection was modified; enumeration operation may not execute.</p>
  </blockquote>
  
  <pre><code>#r "System.Windows.Forms.DataVisualization.dll"
  
  open System.Drawing
  open System.Collections.ObjectModel
  open System.Windows.Forms
  open System.Windows.Forms.DataVisualization.Charting
  
  /// Add data series of the specified chart type to a chart
  let addSeries typ (chart:Chart) =
      let series = new Series(ChartType = typ)
      chart.Series.Add(series)
      series
  
  /// Create form with chart and add the first chart series
  let createChart typ =
      let chart = new Chart(Dock = DockStyle.Fill, 
                            Palette = ChartColorPalette.Pastel)
      let mainForm = new Form(Visible = true, Width = 700, Height = 500)
      let area = new ChartArea()
      area.AxisX.MajorGrid.LineColor &lt;- Color.LightGray
      area.AxisY.MajorGrid.LineColor &lt;- Color.LightGray
      mainForm.Controls.Add(chart)
      chart.ChartAreas.Add(area)
      chart, addSeries typ chart
  
  let numbers = 
      seq { while true do for i in 0.0 .. 0.1 .. 45.0 do yield i }
      |&gt; Seq.map sin
  
  let dataWindow = new ObservableCollection&lt;double&gt;()
  
  numbers
  |&gt; Seq.take 100
  |&gt; Seq.iter dataWindow.Add
  
  let chart, series = createChart SeriesChartType.Line
  series.BorderWidth &lt;- 3
  series.Points.DataBindY(dataWindow)
  
  async{
      for number in numbers do
          series.Points.RemoveAt(0)
          series.Points.Add(number) |&gt; ignore
  }
  |&gt; Async.Start
  </code></pre>