title: Pass in arrays for x and y values to use in pie Chart in MVC?
body: <p>Using the built-in <a href="http://www.w3schools.com/aspnet/webpages_chart.asp" rel="nofollow">Chart in Web Helpers</a>, I was able to bind my data to build a chart, but only if it was a bar chart. I want to make a pie chart. Every example shows creating an array for x and y values by hard-coding them. For example, </p>
  
  <pre><code>       xValue: new[] {  "Peter", "Andrew", "Julie", "Mary", "Dave" }, 
         yValues: new[] { "2", "6", "4", "5", "3" }) 
  </code></pre>
  
  <p>I went through probably the longest way possible to get my information set up in two arrays and it isn't working. There is no error, it just displays a white screen. When debugging, the values come through just as expected. Here is my controller:</p>
  
  <pre><code> var query = string.Format("Select C.* from Cards C Left Join CardDecks CD ON CD.CardID = C.CardID Where DeckID = {0}", id);
   var cardlist = db.Cards.SqlQuery(query).ToList();
   var piearray = cardlist.Select(t =&gt; t.MainType.Title).ToList();
   var pievalues = piearray.GroupBy(c =&gt; c, (a, b) =&gt; string.Format("{0} {1}", b.Count(), a)).ToArray();
              string first = " ";
              string second = " ";
              string xvalues = " ";
              string yvalues = " ";
              List&lt;String&gt; xx = new List&lt;string&gt;();
              List&lt;String&gt; yy = new List&lt;string&gt;();
              foreach (var item in pievalues)
              {
                  first = item.ToString().Substring(0, item.IndexOf(" "));
                  second = item.ToString().Substring(item.IndexOf(" ") + 1);
                  xx.Add(first);
                  yy.Add(second);
              }
              for (int i = 0; i &lt; xx.Count; i++)
              {
  
                  if (i == xx.Count - 1)
                  {
                      xvalues = xvalues + xx[i];
                  }
                  else
                  {
                      xvalues = xvalues + xx[i] + " , ";
                  }
  
              }
              string[] XValue = xvalues.Split(',');
  
              for (int i = 0; i &lt; yy.Count; i++)
              {
  
                  if (i == yy.Count - 1)
                  {
                      yvalues = yvalues + yy[i];
                  }
                  else
                  {
                      yvalues = yvalues + yy[i] + " , ";
                  }
  
              }
              string[] YValue = yvalues.Split(',');
              var myChart = new Chart(width: 200, height: 200)
              .AddSeries(chartType: "Pie", xValue: XValue, xField: "X Field",
              yValues: YValue , yFields: "Y Fields").Write();
              var vm = new ViewDeck();
              vm.Chart = myChart;  
              //More vm.views = view
              return View(vm);
  </code></pre>
  
  <p>Here is part of my Model:</p>
  
  <pre><code>public Chart Chart { get; set; }
  </code></pre>
  
  <p>Here is part of my View:</p>
  
  <pre><code>@Model.Chart
  </code></pre>
  
  <p>I would like to avoid using 3rd party plug-ins. Any help is appreciated. :)</p>