【问题标题】:Get data from several series Highcharts从几个系列的Highcharts中获取数据
【发布时间】:2015-01-19 07:49:44
【问题描述】:

我正在尝试显示具有 2 个系列的 Highcharts 图形来比较数据。

我正在使用以下 javascript 代码:

$(function () {
$.getJSON('test.php', function (data, data2) {

    // create the chart
    $('#container').highcharts('StockChart', {
        chart: {
            alignTicks: false
        },

        rangeSelector: {
            selected: 1
        },

        title: {
            text: 'AAPL Stock Volume'
        },
    plotOptions: {
        column: {
            stacking: 'normal',

        }
    },
        series: [{
            type: 'column',

            name: 'AAPL Stock Volume',
            data: data,
            dataGrouping: {
                units: [[
                    'week', // unit name
                    [1] // allowed multiples
                ], [
                    'month',
                    [1, 2, 3, 4, 6]
                ]]
            }
        },{

            type: 'column',
            name: 'AAPL Stock Volume',
            data: data,
            dataGrouping: {
                units: [[
                    'week', // unit name
                    [1] // allowed multiples
                ], [
                    'month',
                    [1, 2, 3, 4, 6]
                ]]
            }
        }]
    });
});

});

还有这个 PHP 代码:

$arr = array([1147651200000,1],[1147737600000,3],[1147824000000,1]);

$arr2 = array([1147651200000,1],[1147737600000,3],[1147824000000,1]);

echo json_encode($arr, $arr2);?>

目前,我只有一个空白页,但如果只传输一个数组,它可以工作。

我做了不同的测试,我的问题是 json_encode 函数只接受一个参数。我的问题如下:如何将两个数组传输到 php 文件?

【问题讨论】:

  • 把两个数组放到另一个数组中?

标签: json highcharts series


【解决方案1】:

我终于解决了我的问题。感谢 John Zwinck 的想法。

$(function () {
$.getJSON('test.php', function (data) {

    console.log(data);

    // create the chart
    $('#container').highcharts('StockChart', {
        chart: {
            alignTicks: false
        },

        rangeSelector: {
            selected: 1
        },

        title: {
            text: 'AAPL Stock Volume'
        },
    plotOptions: {
        column: {
            stacking: 'normal',

        }
    },
        series: [{
            type: 'column',

            name: 'AAPL Stock Volume',
            data: data.arr1,
            dataGrouping: {
                units: [[
                    'week', // unit name
                    [1] // allowed multiples
                ], [
                    'month',
                    [1, 2, 3, 4, 6]
                ]]
            }
        },{

            type: 'column',
            name: 'AAPL Stock Volume',
            data: data.arr2,
            dataGrouping: {
                units: [[
                    'week', // unit name
                    [1] // allowed multiples
                ], [
                    'month',
                    [1, 2, 3, 4, 6]
                ]]
            }
        }]
    });
});

});

$arr1 = array([1147651200000,4],[1147737600000,3],[1147824000000,6]);

$arr2 = array([1147651200000,4],[1147737600000,8],[1147824000000,2]);

echo json_encode(array('arr1' => $arr1, 'arr2' => $arr2));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 2012-12-19
    • 2013-05-27
    • 2011-11-11
    • 2013-06-10
    • 1970-01-01
    • 2019-08-10
    相关资源
    最近更新 更多