制作一个简单的二维数组

时间:2018-01-22 14:31:18

标签: javascript jquery

我尝试创建这样的实时图表:http://www.flotcharts.org/flot/examples/ajax/index.html

问题是我需要以下数据:

var rawData = [
[1325347200000, 60], [1328025600000, 100], [1330531200000, 15], [1333209600000, 50]
];



$(document).ready(function () {
    var rx_bytes = [];
    var iteration = 0;

    //Options
    var options = {
        lines: {
            show: true
        },
        points: {
            show: true
        },
        xaxis: {
            tickDecimals: 0,
            tickSize: 1
        }
    };

    //Initial Plot
    $.plot("#networkStats", rx_bytes, options);

    function getStatistics() {
        iteration++;

         $.ajax({
            url: '/getStatistics',
            type: 'post',
             dataType: 'json',
            success: function (statistics) {
                console.log(statistics);
                var network = statistics.networks.eth0;
                rx_bytes.push({
                    index: iteration,
                    data: network.rx_bytes
                });
                console.log(rx_bytes);

                //Plot
                $.plot("#cpuStats", [rx_bytes], options);
                //get data again
                getStatistics();
            }
        });
    }

    getStatistics();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;
&#13;
&#13;

我的数组输出如下:http://prntscr.com/i3y8ve

如何制作如上所示的阵列?

1 个答案:

答案 0 :(得分:3)

这应解决它:

          rx_bytes.push([
                iteration,
                network.rx_bytes
            ]);