title: creating Chart for mvc3 razor using database
body: <p>I'm new to asp.net mvc3 and been reading to a lot of posts in stackoverflow on Chart for MVC3 razor.</p>
  
  <p>However, i could not create a chart for this. Basically this is my sql query</p>
  
  <pre><code>SELECT COUNT(RequestStatus) AS Expr1, RequestStatus
  FROM Request
  GROUP BY RequestStatus
  </code></pre>
  
  <p>So far, in my control view, this is my code:</p>
  
  <pre><code>public ActionResult RequestReport()
  { 
      var result = from p in db.Requests
                   group p by p.RequestStatus into pgroup
                   let count = pgroup.Count()
                   orderby count
                   select new { Count = count, RequestStatus = pgroup.Key }.ToString();
  
      var x = new [] {result};    
  
      Chart chart = new Chart(600, 400)
          .AddSeries(yValues: x , yFields:"Count")
      .AddTitle("Request Statistic");
  
      this.ViewBag.Chart = chart;      
  
      return View();
  }
  </code></pre>
  
  <p>and
  in View :</p>
  
  <pre><code>@ViewBag.Chart.Write()
  </code></pre>
  
  <p>please help me solve this issue. i could not find a simple tutorial for this.</p>
  
  <p>ive made some changes on the code in controller.</p>
  
  <pre><code>using (var db = new ITAMMVCDBEntities())
              {
                  var rs = db.Requests.GroupBy(o=&gt;o.RequestStatus).ToList();
                  var result = from o in db.Requests
                               group o by o.RequestStatus
                                   into g
                                   select new
                                   {
                                       result = g.Count()
                                   };
  
              Chart chart = new Chart(600, 400)
                  .AddSeries(
                          xValue: rs.Select(x=&gt;x.Key).ToArray() ,
                          yValues: result.ToArray()
                        )
             .AddTitle("Request Statistic");
  
              this.ViewBag.Chart = chart;      
  
              return View();
          }
  </code></pre>
  
  <p>now i get this error msg when run </p>
  
  <pre><code>Series data points do not support values of type &lt;&gt;f__AnonymousType1`1[System.Int32] only values of these types can be used: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort.
  </code></pre>
  
  <p>i think my xValue is okay as it displays by group 
  but problem populationg yValue which will display the value of each group</p>