Echarts动态数据可视化学习(1)通过js自动定时产生动态数组数据

       /*创建随机数数组*/
    var data = [parseFloat(Math.random() * 100).toFixed(2)];

    /*创建数组函数*/
    function addData(shift) {
        data.push(parseFloat(Math.random() * 100).toFixed(2));

        if (shift) {
            data.shift();
        }

    }

    for (var i = 1; i < 5; i++) {
        addData();
    }
    
    /*定时刷新数据*/
    setInterval(function () {
        addData(true);//保证每次产生的数组是5个元素;
        console.log(data);
    }, 1 * 1000)

posted on 2020-02-03 18:04  漏刻有时  阅读(40)  评论(0)    收藏  举报