title: How to use JSON data in creating a chart with chartjs?
body: <p>In my controller I have an <code>Action</code> method that will find all questions in a table called <code>Questions</code>, and the answers for each question.
  This Action is of type <code>ContentResult</code> that will return a result serialized in Json format.</p>
  
  <pre><code>public ContentResult GetData()
  {
      var datalistQuestions = db.Questions.ToList();
      List&lt;PsychTestViewModel&gt; questionlist = new List&lt;PsychTestViewModel&gt;();
      List&lt;PsychTestViewModel&gt; questionanswerslist = new List&lt;PsychTestViewModel&gt;();
      PsychTestViewModel ptvmodel = new PsychTestViewModel();
  
      foreach (var question in datalistQuestions)
      {
          PsychTestViewModel ptvm = new PsychTestViewModel();
          ptvm.QuestionID = question.QuestionID;
          ptvm.Question = question.Question;
          questionlist.Add(ptvm);
  
          ViewBag.questionlist = questionlist;
  
          var agree = //query
          var somewhatAgree = //query
          var disagree = //query
  
          int Agree = agree.Count();
          int SomewhatAgree = somewhatAgree.Count();
          int Disagree = disagree.Count();
  
          ptvmodel.countAgree = Agree;
          ptvmodel.countSomewhatAgree = SomewhatAgree;
          ptvmodel.countDisagree = Disagree;
  
          questionanswerslist.Add(ptvmodel);
          ViewBag.questionanswerslist = questionanswerslist;
      }
  
      return Content(JsonConvert.SerializeObject(ptvmodel), "application/json");
  }
  </code></pre>
  
  <p>Now, my problem is the pie chart is not being created and I don't quite know how to push the values to my data structure? 
  What should I be doing instead?</p>
  
  <p>Here is my script:</p>
  
  <pre><code>@section Scripts {
      &lt;script type="text/javascript"&gt;
             var PieChartData = {
                      labels: [],
                      datasets: [
                          {
                          label: "Agree",
                          backgroundColor:"#f990a7",
                          borderWidth: 2,
                          data: []
                          },
                      {
  
                          label: "Somewhat Agree",
                          backgroundColor: "#aad2ed",
                          borderWidth: 2,
                          data: []
                      },
                      {
                          label: "Disgree",
                          backgroundColor: "#9966FF",
                          borderWidth: 2,
                          data: []
                          },
  
                      ]
              };
  
              $.getJSON("/PsychTest/GetData/", function (data) {
              for (var i = 0; i &lt;= data.length - 1; i++) {
                  PieChartData.datasets[0].data.push(data[i].countAgree);
                  PieChartData.datasets[1].data.push(data[i].countSomewhatAgree);
                  PieChartData.datasets[2].data.push(data[i].countDisagree);
              }
  
              var ctx = document.getElementById("pie-chart").getContext("2d");
  
              var myLineChart = new Chart(ctx,
                  {
                      type: 'pie',
                      data: PieChartData,
                      options:
                      {
                          responsive: true,
                          maintainaspectratio: true,
                          legend:
                          {
                              position : 'right'
                          }
                      }
                  });
          });
  
  &lt;/script&gt;
  </code></pre>