Highcharts(柱形图)不显示任何空白的html页面

时间:2014-12-01 05:27:59

标签: javascript php html json highcharts

我尝试使用Highcharts教程中给出的柱形图示例。这段代码应该可以正常工作有人请帮我弄清问题。我附上下面的代码。我不知道为什么它只显示空白页。

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Column chart with data from MySQL using Highcharts</title>
    <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">
    $(document).ready(function() {
        var options = {
            chart: {
                renderTo: 'container',
                type: 'column',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'Project Requests',
                x: -20 //center
            },
            subtitle: {
                text: '',
                x: -20
            },
            xAxis: {
                categories: []
            },
            yAxis: {
                title: {
                    text: 'Requests'
                },
                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: []
        }

        $.getJSON("data.php", function(json) {
            options.xAxis.categories = json[0]['data'];
            options.series[0] = json[1];
            options.series[1] = json[2];
            options.series[2] = json[3];
            chart = new Highcharts.Chart(options);
        });
    });
    </script>
</head>
<body>
    <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>

这是data.php。我认为这个php没什么不对。

<?php
  $con = mysql_connect("localhost","*****","*******");

  if (!$con) {
     die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("test_youtube", $con);

  $query = mysql_query("SELECT month, wordpress, codeigniter, highcharts FROM project_requests");

  $category = array();
  $category['name'] = 'Month';

  $series1 = array();
  $series1['name'] = 'Wordpress';

  $series2 = array();
  $series2['name'] = 'CodeIgniter';

  $series3 = array();
  $series3['name'] = 'Highcharts';


  while($r = mysql_fetch_array($query)) {
     $category['data'][] = $r['month'];
     $series1['data'][] = $r['wordpress'];
     $series2['data'][] = $r['codeigniter'];
     $series3['data'][] = $r['highcharts'];   
  }

  $result = array();
  array_push($result,$category);
  array_push($result,$series1);
  array_push($result,$series2);
  array_push($result,$series3);


  print json_encode($result, JSON_NUMERIC_CHECK);

  mysql_close($con);
?> 

0 个答案:

没有答案