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 代码

我想在图表 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() 并将点添加到系列之一。老实说,我没有数据,所以这只是概念。

于 2013-04-22T09:43:11.540 回答