如何在饼图HighChart中显示json数据?

Sad*_*utu 2 highcharts asp.net-mvc-3 pie-chart

我所有的json数据都是这样的

 [ "Data":[ 
 {"Id":"1  ","EmployeeName":Anil},
 ]
Run Code Online (Sandbox Code Playgroud)

这是我从我的控制器动作

       public ActionResult Index()
    { 
        var data = GetData();
        return View();
    }

    public JsonResult GetData()
    {
        int Param1;
        Param1 = 1;     
       var EmployeeDetails = db.EmployeeDetails.ToList<EmployeeDetail>().Select(e =>  
        new
         {
        id=e.EmployeId,
        Name = e.EmployeeName
       });
        return Json(EmployeeDetails , JsonRequestBehavior.AllowGet);
    }
Run Code Online (Sandbox Code Playgroud)

现在我想把这个json数据变成饼图.我可以这样做吗

Sof*_*erd 5

这里不是在action方法中调用你的jsonresult方法,而是使用$ .getJSON方法

  public ActionResult Index()
    { 

    return View();
     }

  public JsonResult GetData()
   {
    int Param1;
    Param1 = 1;     
     var EmployeeDetails = db.EmployeeDetails.ToList<EmployeeDetail>().Select(e =>  
    new
     {
    id=e.EmployeId,
    Name = e.EmployeeName
   });
    return Json(EmployeeDetails , JsonRequestBehavior.AllowGet);
  }
Run Code Online (Sandbox Code Playgroud)

在这里你可以像这样调用你的方法并将它绑定到你的图表

     <script type="text/javascript">
  $(function () {
      $.getJSON('<%= Url.Action("YourMethod","YourControllerName") %>', {}, function (data) {
          var json = data;              
          var jsondata = [];              
          for (var i in json) {
             // var serie = new Array(json[i].Projects, json[i].Bugs);
              jsondata.push([json[i].EmployeId, json[i].EmployeeName]);
          }              
      var chart = new Highcharts.Chart({
          chart: {
              renderTo: 'container',
              type: 'pie',
               plotBackgroundColor: null,
               plotBorderWidth: null,
               plotShadow: false
          },
           title: {
               text: 'Resource Reports of BugTracker'
           },

          plotOptions: {
              pie: {
                  showInLegend: true,
                  animation: false,
                  allowPointSelect: true,
                  cursor: 'pointer'
              }
          },
          legend: {
              enabled: true
          },
          series: [{
              type: 'pie',                 
              data: jsondata
          }]
      });
      });
  });
    </script>
Run Code Online (Sandbox Code Playgroud)