echarts 折线图实时更新

echarts yekong 1675℃

wanjunshijie 2021-05-23 at 21.50.14
wanjunshijie 2021-05-23 at 21.50.33

    function randomNum(minNum, maxNum) {
        switch (arguments.length) {
            case 1:
                return parseInt(Math.random() * minNum + 1, 10);
                break;
            case 2:
                return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
                break;
            default:
                return 0;
                break;
        }
    }
        data: {
            select1: 0,
            select2: 0,
            qiaolist: [
                {
                    title: '解放路高架桥',
                    kualist: [
                        {
                            title: '第9跨',
                            Latlong: [117.398863, 32.945336],
                            yingli: [
                                {
                                    Latlong: [117.39888104459192, 32.945373907654],
                                    title: '应力1',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39887879882815, 32.945363492490245],
                                    title: '应力2',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39887596065641, 32.94534873681981],
                                    title: '应力3',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39887393881378, 32.94533641308471],
                                    title: '应力4',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39886822167739, 32.94532222395518],
                                    title: '应力5',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.3988646843747, 32.94531437566673],
                                    title: '应力6',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39886260802945, 32.94529854562304],
                                    title: '应力7',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39885833904913, 32.94528125957426],
                                    title: '应力8',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                },]
                        },
                        {
                            title: '第10跨',
                            Latlong: [117.398903, 32.945483],
                            yingli: [
                                {
                                    Latlong: [117.3988839131774, 32.94539264000091],
                                    title: '应力1',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39888503605928, 32.945401161495795],
                                    title: '应力2',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39888840470495, 32.94541252348767],
                                    title: '应力3',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39891836202702, 32.94551506886539],
                                    title: '应力4',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39889251911438, 32.94542508655274],
                                    title: '应力5',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39889251911438, 32.945437395373865],
                                    title: '应力6',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39890021847948, 32.94546114183381],
                                    title: '应力7',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39890246424325, 32.94548102530502],
                                    title: '应力8',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39891836202702, 32.94551506886539],
                                    title: '应力9',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39892379899912, 32.94553594153541],
                                    title: '应力10',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                }, {
                                    Latlong: [117.39891655195656, 32.945494451926066],
                                    title: '应力11',
                                    data: [100, 102, 96, 90, 97, 98, 105]
                                },]
                        }]
                },
                {
                    title: '胜利路高架桥',
                    kualist: [
                        {
                            title: '第14跨',
                            Latlong: [117.399105, 32.94543],
                            yingli: [{
                                Latlong: [117.39904006539112, 32.94545429333004],
                                title: '应力1',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39904696112897, 32.94545283968064],
                                title: '应力2',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39906764834258, 32.945445571433275],
                                title: '应力3',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39908833555619, 32.94544411778373],
                                title: '应力4',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39911419457317, 32.945435395885966],
                                title: '应力5',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39913761015507, 32.94542731191742],
                                title: '应力6',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39912638133619, 32.94543393974421],
                                title: '应力7',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39905795041909, 32.94544820659176],
                                title: '应力8',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39912638133619, 32.94543393974421],
                                title: '应力9',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.399099475708, 32.94543685863036],
                                title: '应力10',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39918369184956, 32.945418868814194],
                                title: '应力11',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39915936060929, 32.94542372806232],
                                title: '应力12',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39916834366439, 32.94542562172725],
                                title: '应力13',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            },]
                        }, {
                            title: '第16跨',
                            Latlong: [117.398616, 32.945533],
                            yingli: [{
                                Latlong: [117.39879324978985, 32.945494016539186],
                                title: '应力1',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39877416079777, 32.94550064436094],
                                title: '应力2',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39856305900292, 32.945543251774524],
                                title: '应力3',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39863492344372, 32.94552904930563],
                                title: '应力4',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39874925322498, 32.9455021070613],
                                title: '应力5',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39858306670564, 32.9455409271494],
                                title: '应力6',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39860103281583, 32.9455342993307],
                                title: '应力7',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39861226163471, 32.94553145883682],
                                title: '应力8',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39865156250077, 32.94552388418602],
                                title: '应力9',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39872454982346, 32.94551062854553],
                                title: '应力10',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39868861760306, 32.94551630953456],
                                title: '应力11',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            }, {
                                Latlong: [117.39867299560568, 32.94551940128461],
                                title: '应力12',
                                data: [100, 102, 96, 90, 97, 98, 105]
                            },]
                        }]
                }],
            formInline: {
                sbstyle: '1',
            },
        },
        
alaEchart9: function () {
                var that = this;
                var data = this.qiaolist[this.select1].kualist[this.select2].yingli;
                datatime = [];
                for (var i = 0; i < data.length; i++) {
                    datatime.push(moment((moment().unix() - (i * 600)) * 1000).format("HH:mm:ss"))
                }
                var datax = [];
                for (var i = 0; i < data.length; i++) {
                    var data3 = [];
                    for (var s = 0; s < 10; s++) {
                        data3.push(randomNum(0, 20))
                    }
                    var data2 = {
                        name: '裂缝监测' + (i + 1),
                        type: 'line',
                        data: data3,
                        symbolSize: 1,
                        symbol: 'circle',
                        smooth: true,
                        yAxisIndex: 0,
                        showSymbol: false,
                        lineStyle: {
                            width: 2,
                        },
                    };
                    datax.push(data2)
                }
                var echartsx = echarts.init(document.getElementById("alaEchart9"));
                var option = {
                    tooltip: {
                        trigger: "axis",
                        axisPointer: {
                            type: "shadow",
                            textStyle: {
                                color: "#fff"
                            }
                        },
                    },
                    grid: {
                        left: '1%',
                        right: '2%',
                        bottom: '6px',
                        top: '5%',
                        containLabel: true
                    },
                    calculable: true,
                    xAxis: [{
                        type: "category",
                        axisLine: {
                            lineStyle: {
                                color: "#2a527f",
                            }
                        },
                        axisLabel: {
                            textStyle: {
                                color: '#b1ecff'
                            }
                        },
                        splitLine: {
                            show: false
                        },
                        axisTick: {
                            show: false
                        },
                        data: datatime,
                        boundaryGap: false
                    }],
                    yAxis: [
                        {
                            type: "value",
                            splitLine: {
                                show: false
                            },
                            axisLine: {
                                lineStyle: {
                                    color: "#2a527f",
                                }
                            },
                            axisLabel: {
                                textStyle: {
                                    color: '#b1ecff'
                                }
                            },

                        }],
                    series: datax
                };
                echartsx.setOption(
                    option
                );
                setInterval(function (){
                    option.xAxis[0].data.push(moment().format("HH:mm:ss"));
                    option.xAxis[0].data.splice(0, 1);
                    var datax = option.series;
                    for (var i = 0; i < datax.length; i++) {
                        datax[i].data.push(randomNum(0, 20))
                        datax[i].data.splice(0, 1)
                    }
                    echartsx.setOption(option)
                }, 600000)
            },
喜欢 (3)