的Ajax highcharts饼图不显示数据

的Ajax highcharts饼图不显示数据

问题描述:

这是我的代码:的Ajax highcharts饼图不显示数据

$.ajax({ 
url: 'dashboard/gender', 
type: 'post', 
async: true, 
dataType: "json", 
success: function (data) { 
    visitorData(data); 
} 
}); 

function visitorData (data) { 
$('#gender-pie').highcharts({ 
chart: { 
      plotBackgroundColor: null, 
      plotBorderWidth: null, 
      plotShadow: false, 
      type: 'pie' 
     }, 
     title: { 
      text: 'Genders' 
     }, 
     tooltip: { 
      pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' 
     }, 
     plotOptions: { 
      pie: { 
       allowPointSelect: true, 
       cursor: 'pointer', 
       dataLabels: { 
        enabled: false 
       }, 
       showInLegend: true 
      } 
     }, 
series: data, 
}); 
} 

下面是响应:{ “男性”:9 “女”:2}

我的控制器200确定。正确传递数据。但数据不在我的分区内。标题显示正确。

+0

我实际上解析我的数据转换成JSON发送它们(从控制器功能)之前,所以这不是我的情况。 @将 –

您的系列数据的JSON格式不正确。它应该采用以下格式:

series: [{ 
    data: [{ 
     name: 'Males', 
     y: 9 
    }, { 
     name: 'Females', 
     y: 2 
    }] 
}] 

Working JSFiddle example