如何接收要在Highcharts中使用的系列数据?例如:
series: [{
type: 'pie',
name: 'Jobs',
data: [
{name: 'Single job customers', y: jobsSingle, color: colours.lightYellow, },
{name: '2 job repeats', y: jobsDouble, color: colours.midYellow},
{name: '3+ job customers', y: jobsMore, color: colours.yellow},
]
}]
如何使数据部分成为AJAX调用的函数?
我试过了:
data: function() {
return [
{name: 'Single job customers', y: jobsSingle, color: colours.lightYellow, },
{name: '2 job repeats', y: jobsDouble, color: colours.midYellow},
{name: '3+ job customers', y: jobsMore, color: colours.yellow},
]
}
只是为了测试它是否会解析从函数返回的数据,但这不起作用。
答案 0 :(得分:0)
我找到了一种简单的方法:
function createSurveyChart() {
$.ajax({
url: ROOT + 'Ajax',
data: {
call: 'survey->spendingPie'
},
dataType: 'json',
type: 'POST',
async: true,
success: function(returned) {
$('#surveyChart').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
width: 240,
},
exporting: {enabled: false},
credits: {enabled: false},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: {point.y} <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: false,
cursor: 'pointer',
dataLabels: {
enabled: false,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>:{point.y}{point.percentage:.1f} %'
}
}
},
series: [{
type: 'pie',
name: 'Jobs',
data: returned
}]
});
}
})
}