我有个ajax电话
$(function () {
$.ajax({
url: '../../getdaily.php',
type:'POST',
dataType: '',
success: function(output_string){
console.log(output_string);
},
error: function (xhr, ajaxOptions, thrownError){
console.log(xhr.statusText);
console.log(thrownError);
}
});
});console.log会输出..。
[{"name":"Test-Cases","y":118},{"name":"White-Box","y":43},{"name":"Priority","y":44}]我可以很容易地将它粘贴到我的data :中,获得我想要的片段,如下所示
...
series: [{
type: 'pie',
name: 'Browser share',
data: [{"name":"Test-Cases","y":118},{"name":"White-Box","y":43},{"name":"Priority","y":44}]
}]
...

我的问题是如何让output_string进入data : <here>高级图表。我尝试过各种方法,作为一个变量传入,并开始在这个问题上旋转,但不确定原因。
我用在高级图表上的实际代码并传递给了一个id.
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [{"name":"Test-Cases","y":118},{"name":"White-Box","y":43},{"name":"Priority","y":44}]
}]
});为了覆盖php文件,下面是部分结尾
...
$mysqli->real_query("SELECT priority FROM daily");
$rows2 = array();
$numb2 = 0;
$res2 = $mysqli->use_result();
$rows2['name'] = 'Priority';
while($r2 = $res2->fetch_assoc()) {
$numb2+= $r2['priority'];
$rows2['y'] = $numb2;
}
$result = array();
array_push($result,$rows);
array_push($result,$rows1);
array_push($result,$rows2);
echo json_encode($result);发布于 2015-02-23 04:12:54
只需将highcharts包装在函数中,将ajax响应作为函数的参数传递,并将数据(在参数中)加载到high charts,如下所示:
function my_chart(response) {
$('#container').highcharts({
...
...
series: [{
type: 'pie',
name: 'Browser share',
data: response
}]
});
}并在ajax响应中调用函数,如:
$(function () {
$.ajax({
url: '../../getdaily.php',
type:'POST',
dataType: '',
success: function(output_string){
//call my_chart function
var parsed_response = jQuery.parseJSON(output_string);
my_chart(parsed_response);
},
error: function (xhr, ajaxOptions, thrownError){
console.log(xhr.statusText);
console.log(thrownError);
}
});
});https://stackoverflow.com/questions/28666481
复制相似问题