0

HighStock に問題があり、JSON から別のシリーズが必要です。

get_json.phpの私のコード

include('config.php');

$cp = $_REQUEST["c_prot"];

$r=("SELECT * FROM data WHERE cp='$cp'"); 
$result=mysql_query($r);

while($row = mysql_fetch_array($result)){
    $date= strtotime($row['cas'])*1000;  // timestamp
    $values=hexdec($row['data']);        // series1 
    $val=hexdec($row['src']);            // series2

    $array[]=array($date, $values,$val);  //output array
}
echo json_encode($array);

JSON 出力は正しい形式です: [1364852734000, 557, 2884],....しかし、問題は、JSON から Highstock コードに 2 番目のシリーズを追加する方法が見つからなかったことです。

グラフに表示したい x軸: タイムスタンプ y軸: series1->data series2->src

グラフは x 軸のタイムスタンプと y 軸のデータのみに表示されるようになりましたが、series2 は機能しません:/

証券コード:

<script>
$(function () {
    $.getJSON('http://localhost/vojto/get_json.php?c_prot=<?=$_REQUEST['
    c_prot '];?>', function (data) {

        // Create the chart
        $('#container').highcharts('StockChart', {

            chart: { //zooming
                zoomType: 'x',
                height: 400,
            },

            legend: { //legenda
                enabled: true,
                align: 'left',
                backgroundColor: '#FCFFC5',
                borderColor: 'black',
                borderWidth: 1,
                layout: 'vertical',
                verticalAlign: 'top',
                y: 100,
                shadow: true
            },

            rangeSelector: { //range selector
                buttonTheme: {
                    width: 40,

                },

                buttonSpacing: 3, //mezera mezi buttony
                enabled: true,

                buttons: [{
                    type: 'minute',
                    count: 60,
                    text: 'Hour'
                }, {
                    type: 'day',
                    count: 1,
                    text: 'Day'
                }, {
                    type: 'week',
                    count: 1,
                    text: 'Week'
                }, {
                    type: 'all',
                    text: 'Reset'
                }]
            },

            title: { //title grafu
                text: 'Chart'
            },

            series: [{ //serie
                name: 'Data',
                data: data,
                color: '#57c72f',
                marker: {
                    enabled: true,
                    radius: 3
                },
                shadow: true,
                tooltip: {
                    valueDecimals: 2
                }
            }],

            xAxis: { // X-osa
                type: 'datetime',
                title: {
                    text: 'Date/time axis',
                },
                minRange: 600000,

            },
            yAxis: {
                min: 0,
            },
            navigator: {
                series: {
                    color: '#57c72f',
                    fillOpacity: 0.3,
                }
            },
            credits: {
                enabled: false
            },

            tooltip: { // formátování hodnot po najetí kurzoru... hover
                formatter: function () {
                    var s = '<b>' + Highcharts.dateFormat('DateTime ' + '%d-%m-%y ' + '%H:%M:%S', this.x) + '</b>';

                    $.each(this.points, function (i, point) {
                        s += '<br/>Data value : ' + point.y;
                    });

                    /* formát  23-04-13 09:34:27 */
                    return s;
                }
            },
        });
    });
});
</script>
4

1 に答える 1

0

あなたのスクリプトでは:

$array = [];
while($row = mysql_fetch_array($result)){
    $date= strtotime($row['cas'])*1000;  // timestamp
    $values=hexdec($row['data']);        // series1 
    $val=hexdec($row['src']);            // series2

    $array[0][]=array($date, $values);  //output array
    $array[1][]=array($date ,$val); 
}

値を適切なシリーズ インデックスに貼り付ける必要があります。つまり、 $array() を準備して、シリーズの 1 つにポイントを追加できます。正直データがないのであくまでコンセプトです。

于 2013-04-22T09:43:11.540 に答える