Highcharts PhpMySQL:空白页面加载而不是图表 - 如何在highcharts中呈现动态json数据

时间:2014-08-14 11:13:50

标签: php json highcharts

我正在尝试将动态数据加载到div。我已经有了如下所示的json数据

[{"name":"count","data":[94797,77957,85095,81528,78494]},{"name":"net","data":[270205,220410,237440,227395,217985]},{"name":"principal","data":[4.01,0.14,250677.74,228381.02,219001.12]}]

以下是我的代码。请协助诊断问题所在。

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>
    <script src="http://code.highcharts.com/modules/exporting.js"></script>
   <script type="text/javascript">

   $(function () {
                   var chart;        
       $(document).ready(
                         function() {
                          $.getJSON("graph_dpr.php", 
                        function(json) {

                                        chart = new Highcharts.Chart({
                                            chart: {
                                                renderTo: 'container',
                                                type: 'line',
                                                marginRight: 130,
                                                marginBottom: 25
                                        },
                                        title: {
                                            text: 'DPR graph',
                                            x: -20 //center
                                        },
                                        subtitle: {
                                            text: '',
                                            x: -20
                                        },
                                        xAxis: {
                                            categories: ['2014-02-01', '2014-02-02', '2014-02-03', '2014-02-04', '2014-02-05']
                                        },
                                        yAxis: {
                                            title: {
                                                text: 'Principal_Lent'
                                            },
                                            plotLines: [{
                                                value: 0,
                                                width: 1,
                                                color: '#808080'
                                            }]
                                        },
                                        tooltip: {
                                            formatter: function() {
                                                    return '<b>'+ this.series.name +'</b><br/>'+
                                                    this.x +': '+ this.y;
                                            }
                                        },
                                        legend: {
                                            layout: 'vertical',
                                            align: 'right',
                                            verticalAlign: 'top',
                                            x: -10,
                                            y: 100,
                                            borderWidth: 0
                                        },
                                        series: json
        });
    });

});

});         

图表应该加载在body标签内的div下面。

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

请注意:&#34; graph_dpr.php&#34;是检索json数据的页面。

0 个答案:

没有答案