0

我正在从我的控制器返回一个 josn 数据并将其绑定到饼图......但最后我在我的页面中没有得到任何东西......谁能告诉我我在哪里做错了......

     <script type="text/javascript">

    $(function () {
        var chart;
        alert('1');
        $(document).ready(function () {
        var options = {
        chart: {
           renderTo: 'container',
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    defaultSeriesType: 'pie'
        },
        title: {
           text:'Resource Reports'
         },
       plotOptions: {
           pie: {
               allowPointSelect: true,
               cursor: 'pointer',
               dataLabels: {
                   enabled: true,
                   color: '#000000',
                   connectorColor: '#000000',
                   formatter: function () {
                       //return '<b>' + this.point.name + '</b>: ' + this.percentage + ' %';
                   }
               }
           }
       },
        series: [{
           type: 'pie',
           name: 'Fruits',
           data:[]
        }]
     };

            $.getJSON('<%= Url.Action("GetData","JqueryCharts") %>', null, function (data) {
                alert('2');                    
                options.series = json;
                chart = new Highcharts.chart(options);                                  

            });

        });
    });

</script>

这是我的控制器

        public JsonResult GetData()
    {
        //int Param1;
        //Param1 = 1;
        //DataEntitiesModel data = new DataEntitiesModel();
        //var procedure=db.Database.SqlQuery<DataEntitiesModel>("ResourceReports @EmployeeID",new SqlParameter("@EmployeeID", Param1) );
        //var procedure = db.Database.SqlQuery<DataEntitiesModel>("Select * from EmployeeDetails");
        //var data = db.ProjectReports.ToList().Select( e => new
        //{
        //    Id = e.EmployeeID,
        //    Name = e.EmployeeName
        //});
        var EmployeeDetails = db.EmployeeDetails.ToList<EmployeeDetail>().Select(e => new
        {
            id=e.EmployeId,
            Name = e.EmployeeName
        });
        return Json(EmployeeDetails, JsonRequestBehavior.AllowGet);
    }
4

2 回答 2

0

也许?

$.getJSON('<%= Url.Action("GetData","JqueryCharts") %>', null, function (data) { 
            options.series = [{
                type: 'pie',
                name: 'Fruits',
                data:json
            }];
            chart = new Highcharts.chart(options);                                  

        });
于 2012-08-20T14:27:46.930 回答
0

确保您的 json 输出由数字而不是字符串组成。Db 查询通常返回字符串,在将它们转换为 json 之前,您需要将它们转换为 float/int

于 2012-08-20T14:01:14.993 回答