Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何在饼图和图表中显示json数据?_Asp.net Mvc 3_Highcharts_Pie Chart - Fatal编程技术网

Asp.net mvc 3 如何在饼图和图表中显示json数据?

Asp.net mvc 3 如何在饼图和图表中显示json数据?,asp.net-mvc-3,highcharts,pie-chart,Asp.net Mvc 3,Highcharts,Pie Chart,大家好,我有一个json数据,看起来像这样 [ "Data":[ {"Id":"1 ","EmployeeName":Anil}, ] 这是我从控制器操作中获得的 public ActionResult Index() { var data = GetData(); return View(); } public JsonResult GetData() { int Param1;

大家好,我有一个json数据,看起来像这样

 [ "Data":[ 
 {"Id":"1  ","EmployeeName":Anil},
 ]
这是我从控制器操作中获得的

       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);
    }
public ActionResult Index()
{ 
var data=GetData();
返回视图();
}
公共JsonResult GetData()
{
int参数1;
参数1=1;
var EmployeeDetails=db.EmployeeDetails.ToList().Select(e=>
新的
{
id=e.EmployeId,
Name=e.EmployeeName
});
返回Json(EmployeeDetails,JsonRequestBehavior.AllowGet);
}

现在我想把这个json数据做成一个饼图。我怎样才能做到这一点呢?不管你有什么类型的数据,创建一个饼图是相当简单的。请参见此处的工作示例:


在这里,不要在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);
  }
public ActionResult Index()
{ 
返回视图();
}
公共JsonResult GetData()
{
int参数1;
参数1=1;
var EmployeeDetails=db.EmployeeDetails.ToList().Select(e=>
新的
{
id=e.EmployeId,
Name=e.EmployeeName
});
返回Json(EmployeeDetails,JsonRequestBehavior.AllowGet);
}
在这里,您可以像这样调用您的方法并将其绑定到图表

     <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>

$(函数(){
$.getJSON(“”,{},函数(数据){
var json=数据;
var jsondata=[];
for(json中的var i){
//var serie=newarray(json[i].Projects,json[i].bug);
push([json[i].EmployeId,json[i].employeName]);
}              
var图表=新的Highcharts.图表({
图表:{
renderTo:'容器',
键入“pie”,
plotBackgroundColor:null,
plotBorderWidth:null,
plotShadow:false
},
标题:{
文本:“BugTracker的资源报告”
},
打印选项:{
馅饼:{
showInLegend:是的,
动画:错,
allowPointSelect:true,
光标:“指针”
}
},
图例:{
已启用:true
},
系列:[{
键入“pie”,
资料来源:jsondata
}]
});
});
});

您的视图是什么样子的?您是如何尝试设置饼图的?顺便问一下,您的索引操作对
GetData
方法的结果没有任何影响……您是在使用HighCharts还是只想创建一个饼图?Asp.net能够在MVC中生成饼图,而不需要第三方解决方案,而且在线上有大量关于如何使用它的教程。正如nemesv指出的,
var data=GetData()没有执行任何操作。每个切片将表示哪些信息?
     <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>