title: Using Linq to group hourly and get an hourly average
body: <p>I cannot seem to work out how to do this.
  I have an object that has a <code>DateTime</code> property and an <code>int</code></p>
  
  <p>I want to group the <code>DateTime</code> hourly and then have the <code>TimeTaken</code> property averaged per hour.</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class ChartModel
  {
      public DateTime Date { get; set; }
      public int TimeTaken { get; set; }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public ActionResult PopulateResponseTimeChart()
  {
      // selectedItem is a type of IEnumerable&lt;ChartModel&gt;
      var average = selectedItem.GroupBy(x =&gt; x.Date.Date).Select(x =&gt; new { Date = x.Key, Average = x.Average(a =&gt; a.TimeTaken) });
      var data = average.Select(x =&gt; x.Average.ToString(CultureInfo.CurrentUICulture)).ToArray();
      var time = average.Select(x =&gt; x.Date).ToArray();
  
       // Other stuff
   }
  </code></pre>
  
  <p>This above doesn't seem to work. <code>average</code> only contains 1 result, when i'm expecting it to be hourly.
  The reason behind this is I want to use it in the JS libary Highcharts</p>