来自 PHP JSON 的 Highchart Feed 数据


highchart feed data from php json

我正在尝试将json数据提供给highchart,但图形显示为空白,这是我需要的样本:http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/column-rotated-labels/

values.php生成json输出

[["10000164@example",4],["10000166@example",2],["10000173@example",1],["10000177@example",3]]

在索引中.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''s 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 直接放在数据选项中,图表将呈现如下:斯菲德尔