title: Loading data from controller to chart Jquery/ MVC/ C#
body: <p>I have the following controller code to return chart data to jquery.
  UPDATE: I have modified the code as suggested, but still getting error.</p>
  
  <pre><code> public JsonResult GetLeaveDataForPieChart(int user_id)
      {
  
          List&lt;EmployeeLeaveHeader&gt; elh1 = new List&lt;EmployeeLeaveHeader&gt;();
          List&lt;ChartEvent&gt; ch = new List&lt;ChartEvent&gt;();
          elh1 = itlbg1.EmployeeLeaveHeaders.Where(f =&gt; f.Employee_ID == user_id).ToList();
  
      foreach (var item in elh1)
      {
          ChartEvent ce = new ChartEvent();
          ce.value = (item.leaveAvailable * 100).ToString();
          ce.color = item.CompanyLeaves.LeaveTypes.color;
          ce.highlight = "#ffffff";
          ce.label = item.CompanyLeaves.LeaveTypes.typeDescription + " Leave Available";
          ch.Add(ce);
  
          ChartEvent ce1 = new ChartEvent();
          ce1.value = (item.leaveTaken * 100).ToString();
          ce1.color = item.CompanyLeaves.LeaveTypes.color_light;
          ce1.highlight = "#ffffff";
          ce1.label = item.CompanyLeaves.LeaveTypes.typeDescription + " Leave Taken";
          ch.Add(ce1);
      }
  
  
  
      return Json(ch, JsonRequestBehavior.AllowGet);
  
  }
  </code></pre>
  
  <p>I need to retrieve data in jquery so that it is in the required format to be passed to pie data.</p>
  
  <pre><code>(document).ready(function () {
  
      user_id = $("#user_id_1").text();
      $.ajax({
          url: '/Leave/GetLeaveDataForPieChart/',
          cache: false,
          data: { user_id: user_id },
          type: "GET",
          datatype: "json",
          success: function (data) {
              alert(data);
              var pieChartCanvas = $("#pieChart").get(0).getContext("2d");
              var pieChart = new Chart(pieChartCanvas);
              var PieData = $.each(data, function (idx, obj) {
                  var leave = new Object();
  
                      leave.value = obj.value;
                      leave.color = obj.color;
                      leave.highlight = obj.highlight;
                      leave.label = obj.label;
                      alert(leave);
                      return leave;
                  });
  
                      var pieOptions = {
      //pie options..
  
  };
  
                  pieChart.Doughnut(PieData, pieOptions);
              }
          });
  </code></pre>
  
  <p>Can anyone explain how to convert the json data to javascript object to be passed to the pie chart?</p>