title: Creating Google Chart in ASP.NET MVC
body: <p>I was reading this <a href="http://blog.platformular.com/2012/03/20/load-google-chart-by-ajax-using-asp-net-mvc-and-jquery/" rel="nofollow">http://blog.platformular.com/2012/03/20/load-google-chart-by-ajax-using-asp-net-mvc-and-jquery/</a> and this <a href="https://google-developers.appspot.com/chart/interactive/docs/gallery/areachart" rel="nofollow">https://google-developers.appspot.com/chart/interactive/docs/gallery/areachart</a>.  </p>
  
  <p>How can I create an array like this in VB.NET?</p>
  
  <pre><code>    var data = google.visualization.arrayToDataTable([
        ['Year', 'Sales', 'Expenses'],
        ['2004',  1000,      400],
        ['2005',  1170,      460],
        ['2006',  660,       1120],
        ['2007',  1030,      540]
      ]);
  </code></pre>
  
  <p>I need to create it from a query, not from static data like in the article I linked to above:</p>
  
  <pre><code>Dim water = db.Tbl_Hydrations.Where(Function(x) x.Hyd_Create_Date &gt;= firstDay And x.Hyd_Create_Date &lt;= lastDay).ToList
  </code></pre>
  
  <p>If I can create the array, I can display the data in the chart.  Thanks for your help.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I tried this:</p>
  
  <pre><code>Function WeightAreaChartData() As JsonResult
  
      Dim data = New Dictionary(Of String, Object)
  
      data.Add("1", New With {.Name = "China", .Value = "11"})
      data.Add("2", New With {.Name = "China", .Value = "11"})
  
      Return Json(data, JsonRequestBehavior.AllowGet)
  
  End Function
  </code></pre>
  
  <p>But, Google Charts says, "No Data."</p>
  
  <p>The JSON it returns is:</p>
  
  <pre><code>{"1":{"Name":"China","Value":"11"},"2":{"Name":"China","Value":"11"}} 
  </code></pre>
  
  <p><strong>Final Edit:</strong></p>
  
  <p>This is the action I'm using:</p>
  
  <pre><code>&lt;EmployeeAuthorize()&gt;
  Function WeightAreaChartData() As JsonResult
  
      Dim myData = db.Tbl_Weights.Where(Function(x) x.Weight_Employee_ID).OrderBy(Function(x) x.Weight_Create_Date)
  
      Dim data = New List(Of Object)
  
      data.Add(New Object() {"Date", "Your Weight"})
  
      For Each i As Tbl_Weight In myData
  
          data.Add(New Object() {DateTime.Parse(i.Weight_Create_Date).Day, i.Weight_Amount})
  
      Next
  
      Return Json(data, JsonRequestBehavior.AllowGet)
  
  End Function
  </code></pre>