数据不会在Highcharts上回显

时间:2013-05-31 15:04:21

标签: php mysql sql highcharts

我无法将我的数据绘制在高潮图上,但是它出现在源头上,我做错了什么?我不知道我是否使用错误的语法来回显hcdata.php中的字符串。我一直遇到这个问题,让输出显示在实际图表上,我可以看到数据格式正确,它出现如下:

  

[Date.UTC(2013,05,31,10,39,36),20179],   [Date.UTC(2013,05,31,10,30,00),20031],   [Date.UTC(2013,05,31,10,09,36),19684],   [Date.UTC(2013,05,31,09,54,36),19384],   [Date.UTC(2013,05,31,09,39,36),19039],   [Date.UTC(2013,05,31,09,24,36),18763],   [Date.UTC(2013,05,31,09,09,36),18435],   [Date.UTC(2013,05,31,08,54,36),18097],   [Date.UTC(2013,05,31,08,39,36),17788],   [Date.UTC(2013,05,31,08,30,00),17552],   [Date.UTC(2013,05,31,08,09,36),17169],   [Date.UTC(2013,05,31,08,00,00),16940],   [Date.UTC(2013,05,31,07,45,00),16608],   [Date.UTC(2013,05,31,07,30,00),16284],   [Date.UTC(2013,05,31,07,15,00),15922],   [Date.UTC(2013,05,31,06,54,36),15216],   [Date.UTC(2013,05,31,06,39,36),14724],   [Date.UTC(2013,05,31,06,30,00),14352],   [Date.UTC(2013,05,31,06,09,36),13713],   [Date.UTC(2013,05,31,05,54,36),13491],   [Date.UTC(2013,05,31,05,39,36),13660],   [Date.UTC(2013,05,31,05,24,36),13680],   [Date.UTC(2013,05,31,05,09,36),13548],   [Date.UTC(2013,05,31,04,54,36),13327],   [Date.UTC(2013,05,31,04,45,00),13263],   [Date.UTC(2013,05,31,04,30,00),13178],   [Date.UTC(2013,05,31,04,09,36),13105],   [Date.UTC(2013,05,31,03,54,36),13048],   [Date.UTC(2013,05,31,03,39,36),13054],   [Date.UTC(2013,05,31,03,24,36),13079],   [Date.UTC(2013,05,31,03,15,00),13138],   [Date.UTC(2013,05,31,03,00,00),13200],   [Date.UTC(2013,05,31,02,39,36),13330],   [Date.UTC(2013,05,31,02,24,36),13409],   [Date.UTC(2013,05,31,02,15,00),13512],   [Date.UTC(2013,05,31,01,54,36),13675],   [Date.UTC(2013,05,31,01,39,36),13825],   [Date.UTC(2013,05,31,01,24,36),13986],   [Date.UTC(2013,05,31,01,15,00),14143],   [Date.UTC(2013,05,31,00,54,36),13851],   [Date.UTC(2013,05,31,00,39,36),14066],   [Date.UTC(2013,05,31,00,24,36),14303],   [Date.UTC(2013,05,31,00,09,36),14591]

    <?php include "data.php"; ?>
    <?php include "hcdata.php"; ?>


            <!DOCTYPE HTML>
            <html>
        <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>

    <script type="text/javascript" src="''/SQLPHP/js/jquery.min.js"></script>
    <script src="''/SQLPHP/js/highcharts.js"></script>
    <script src="''/SQLPHP/js/modules/exporting.js"></script>
    <script type="text/javascript">
    $(function () {
    var data = [
                [<?php echo $finalString; ?>]
            ];

    data.sort(function(a,b) {
        return a[0] - b[0];
    });

    $('#container').highcharts({
        chart: {
            type: 'spline'
        },
        title: {
            text: 'Forecast vs Actual Load [VM]'
        },
        subtitle: {
            text: 'This chart displays the time and actual forecast load for this    region'
        },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: { // don't display the dummy year
                month: '%e. %b',
                year: '%b'
            }
        },
        yAxis: {
            title: {
                text: 'Actual Load (WM)'
            },
            min: 0
        },
        tooltip: {
            formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                    Highcharts.dateFormat('%e. %b', this.x) +': '+ this.y +' m';
            }
        },

        series: [{
            name: 'Forecast vs Actual Load',
            // Define the data points. All series have a dummy year
            // of 1970/71 in order to be compared on the same x axis. Note
            // that in JavaScript, months start at 0 for January, 1 for February etc.
            data: data
            }]
          });
       });


    </script>
   </head>
<body>

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

</body>
    </html>

1 个答案:

答案 0 :(得分:1)

您的PHP数据插件看起来像是将数据包装在2个[]块中:

var data = [
                [<?php echo $finalString; ?>]
            ];

您需要将整个data集合包装在一个[]中。看起来像这样:

var data = [
                <?php echo $finalString; ?>
            ];

你应该最终得到这个:

[
[Date.UTC(2013,05,31,10,39,36), 20179], [Date.UTC(2013,05,31,10,30,00), 20031], [Date.UTC(2013,05,31,10,09,36), 19684], [Date.UTC(2013,05,31,09,54,36), 19384], [Date.UTC(2013,05,31,09,39,36), 19039], [Date.UTC(2013,05,31,09,24,36), 18763], [Date.UTC(2013,05,31,09,09,36), 18435], [Date.UTC(2013,05,31,08,54,36), 18097], [Date.UTC(2013,05,31,08,39,36), 17788], [Date.UTC(2013,05,31,08,30,00), 17552], [Date.UTC(2013,05,31,08,09,36), 17169], [Date.UTC(2013,05,31,08,00,00), 16940], [Date.UTC(2013,05,31,07,45,00), 16608], [Date.UTC(2013,05,31,07,30,00), 16284], [Date.UTC(2013,05,31,07,15,00), 15922], [Date.UTC(2013,05,31,06,54,36), 15216], [Date.UTC(2013,05,31,06,39,36), 14724], [Date.UTC(2013,05,31,06,30,00), 14352], [Date.UTC(2013,05,31,06,09,36), 13713], [Date.UTC(2013,05,31,05,54,36), 13491], [Date.UTC(2013,05,31,05,39,36), 13660], [Date.UTC(2013,05,31,05,24,36), 13680], [Date.UTC(2013,05,31,05,09,36), 13548], [Date.UTC(2013,05,31,04,54,36), 13327], [Date.UTC(2013,05,31,04,45,00), 13263], [Date.UTC(2013,05,31,04,30,00), 13178], [Date.UTC(2013,05,31,04,09,36), 13105], [Date.UTC(2013,05,31,03,54,36), 13048], [Date.UTC(2013,05,31,03,39,36), 13054], [Date.UTC(2013,05,31,03,24,36), 13079], [Date.UTC(2013,05,31,03,15,00), 13138], [Date.UTC(2013,05,31,03,00,00), 13200], [Date.UTC(2013,05,31,02,39,36), 13330], [Date.UTC(2013,05,31,02,24,36), 13409], [Date.UTC(2013,05,31,02,15,00), 13512], [Date.UTC(2013,05,31,01,54,36), 13675], [Date.UTC(2013,05,31,01,39,36), 13825], [Date.UTC(2013,05,31,01,24,36), 13986], [Date.UTC(2013,05,31,01,15,00), 14143], [Date.UTC(2013,05,31,00,54,36), 13851], [Date.UTC(2013,05,31,00,39,36), 14066], [Date.UTC(2013,05,31,00,24,36), 14303], [Date.UTC(2013,05,31,00,09,36), 14591]
]