Я пытаюсь передать данные json
на highchart, но график выглядит пустым. Это то, что мне нужно: http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/образцы/Highcharts/демо/колонок-повернут-этикетка/
values.php
генерирующий json
выход
[["10000164@example",4],["10000166@example",2],["10000173@example",1],["10000177@example",3]]
Здесь в index.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Bar Chart</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
type: 'column'
},
title: {
text: 'World\ largest cities per 2014'
},
subtitle: {
text: 'Source: <a href="http://en.wikipedia.org/wiki/List_of_cities_proper_by_population">Wikipedia</a>'
},
xAxis: {
type: 'category',
labels: {
rotation: -45,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)'
}
},
legend: {
enabled: false
},
tooltip: {
pointFormat: 'Population in 2008: <b>{point.y:.1f} millions</b>'
},
series: [{
name: 'Population',
data: [],
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
x: 4,
y: 10,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif',
textShadow: '0 0 3px black'
}
}
}]
$.getJSON("values.php", function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});
});
});
</script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>
</body>
</html>
Не могли бы вы построить диаграмму внутри функции обратного вызова, а не сначала определить все параметры? Возможно, попробуйте что-то вроде этого:
$.getJSON('values.php', function (json) {
$('#container').highcharts({
series: [{
data: json
]},
title: {
text: 'Some Title'
},
subtitle: ...
Я не могу выполнить демо-запрос ajax, но если вы поместите этот json прямо в параметр данных, графики будут выглядеть следующим образом: jsfiddle