在Highcharts中从PHP加载JSON编码数据时,条形图不会显示

时间:2012-05-15 20:47:01

标签: php mysql ajax json highcharts

我正在加载存储在MySQL数据库中的数据。 该图表未显示在网页上,但未显示任何其他警告。

我的PHP网页返回一个JSON编码标头,其中包含以下信息:

["John Doe","2","Jane Doe","3"]

加载信息的脚本如下:

var chart;
function requestData() {
    $.ajax({
        url:'includes/bin/get_leaders.php',
        success: function(point) {
            alert(point);
        var series = chart.series[0],
        shift = series.data.length > 20; // shift if the series is longer than 20
        chart.series[0].addPoint(point, true, shift);
    },
    cache: false
});
$(document).ready(function() {
chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        type: 'bar',
        events: {load: requestData}
    },
    title: {
        text: 'Top Agents'
    },
    xAxis: {
        type: 'int',
        title: {text: null}
    },
    yAxis: {
        min: 0,
        title: { text: 'Sales this Week', align: 'low'}
    },
    tooltip: {
        formatter: function() {
            return ''+ this.series.name +': '+ this.y +' sales';
            }
        },
    plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
    legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -100,
            y: 100,
            floating: true,
            borderWidth: 0,
            backgroundColor: '#FFFFFF',
            shadow: false
        },
        credits: {
            enabled: false
        },
    series: [{
        name: 'Sales'        }]
});        
});
});

有什么想法发生了什么? 谢谢!

1 个答案:

答案 0 :(得分:1)

看起来你正在传递[“字符串”,“数字”,“字符串”,“数字”]。 你想要的是你的系列{2,3},然后你的xAxis使用{“John Doe”,“Jane Doe”}的类别列表。