У меня есть вызов 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);
}
});
});
и консоль.log выведет...
[{"name":"Test-Cases","y":118},{"name":"White-Box","y":43},{"name":"Priority","y":44}]
Я могу легко вставить это в мои data :
для высоких диаграмм и получения piechart я ищу так
...
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>
Highcharts data: <here>
. Я пробовал различные способы перехода в переменную и начинаю раскручиваться, не знаю почему.
Фактический код, который я использую для высоких диаграмм и переходящий в идентификатор...
$('#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);
Просто оберните свои 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);
}
});
});