0

我一直在尝试获取 highcharts 来绘制 php 返回的一些数据。我做了很多搜索,但没有任何效果。我可以编写 php 来传递数据,但是它需要,但是你如何让它动态地绘制它??????

我可以将其传递为:[["1372875867","44.8782806"],["1372875885","46.2020226"]] 或 [[1372876686,44.0655823],[1372876693,43.3360596] 等]

但是我如何从 php 输出中获取数据到他们显示的 dyname 示例中??????

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

    <script type="text/javascript" 
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {

Highcharts.setOptions({
    global : {
        useUTC : false
    }
});

// Create the chart
window.chart = new Highcharts.StockChart({
    chart : {
        renderTo : 'container',
        events : {
            load : function() {

                // set up the updating of the chart eachsecond
                var series = this.series[0];
                setInterval(function() {
                    var x = (new Date()).getTime(), 
                    y = Math.round(Math.random() * 100);
                    series.addPoint([x, y], true, true);
                }, 1000);
            }
        }
    },

    rangeSelector: {
        buttons: [{
            count: 1,
            type: 'minute',
            text: '1M'
        }, {
            count: 5,
            type: 'minute',
            text: '5M'
        }, {
            type: 'all',
            text: 'All'
        }],
        inputEnabled: false,
        selected: 0
    },

    title : {
        text : 'Live random data'
    },

    exporting: {
        enabled: false
    },

    series : [{
        name : 'Random data',
        data : (function() {
            // generate an array of random data
            var data = [], time = (new Date()).getTime(), i;

            for( i = -999; i <= 0; i++) {
                data.push([
                    time + i * 1000,
                    Math.round(Math.random() * 100)
                ]);
            }
            return data;
        })()
    }]
        });

    });

    </script>
</head>
<body>
    <script src="../../js/highstock.js"></script>
    <script src="../../js/modules/exporting.js"></script>

    <div id="container" style="height: 500px; min-width: 500px"></div>
</body>
    </html>

我目前的 php 是:

    <?php
    //    include("$_SERVER[DOCUMENT_ROOT]/config/config.php");
    include("adodb5/adodb.inc.php");
    $connection = new COM("ADODB.Connection") or die("Cannot start ADO"); 
    $result_set = $connection->Execute("
            SELECT tag, TIME, value 
            FROM picomp 
            WHERE TIME >= '*-3m' AND tag = 'xxx:xx_xxx.xxx'
            ");

    $result_count = 0;
    //    $labels = array();
    while (!$result_set->EOF) {
$pidate = date("U", strtotime($result_set->fields[1]) );
if ($result_count <> 0){
print ",";
}else{
print "[";
}
    print "[".$pidate.",".$result_set->fields[2]."]";
    //        array_push("{$result_set->fields[2]}");
    $result_count = $result_count +1;
    $result_set->MoveNext();
    //  echo "testing";
    }
    print "];";
4

2 回答 2

0

您可以使用 HighchartsPHP,它是 Highcharts 的包装器,它基本上允许您用 PHP 编写所有 JS 代码。它非常有用且使用起来非常简单。

GitHub 上的 HighchartsPHP

于 2013-07-03T18:14:17.823 回答
0

您的时间戳应该乘以 1000,并且两个值都应该是数字。

请熟悉soultion,如何准备JSON,因为您只打印“as JSON”,但事实并非如此。

看看http://php.net/manual/en/function.json-encode.php,其中介绍了一些示例。

于 2013-07-04T08:51:54.543 回答