From f84e5a87d3aeb665f4a84113e7e67533d2979faf Mon Sep 17 00:00:00 2001 From: chenzeping <ChenZeping02609@163.com> Date: 星期五, 09 四月 2021 15:46:40 +0800 Subject: [PATCH] echarts --- src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue | 253 ++++++++++++++++---------------------------------- 1 files changed, 82 insertions(+), 171 deletions(-) diff --git a/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue b/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue index 3ac2e52..2207d31 100644 --- a/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue +++ b/src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue @@ -1,10 +1,10 @@ <template> - <div style="width:100%;height:2rem;" ref="echarts"></div> + <div style="width:100%;height:2rem;margin-top: 0.3rem" ref="echarts"></div> </template> <script> -import mapApi from '@/api/mapApi' +// import mapApi from '@/api/mapApi' import 'dayjs/locale/es' import dayjs from 'dayjs' @@ -13,184 +13,95 @@ data () { return { myChart: [], - dataDate: [], - value: '', - seriesData: [], - aseries: '', - result: [], - days: dayjs(new Date()).format('YYYYMMDDHHmmss') - } - }, - methods: { - drawChart (result) { - // const result = this.result - this.myChart = this.$echarts.init(this.$refs.echarts) - - // setInterval(function () { - // }, 3000) - const option = { - title: { - text: '鎶樼嚎鍥惧爢鍙�' - }, - tooltip: { - trigger: 'axis' - }, - legend: { - data: ['閭欢钀ラ攢', '鑱旂洘骞垮憡', '瑙嗛骞垮憡', '鐩存帴璁块棶', '鎼滅储寮曟搸'] - }, - grid: { - containLabel: true - }, - toolbox: { - feature: { - saveAsImage: { - show: false - } - } - }, - xAxis: { - type: 'category', - boundaryGap: false, - // data: seriesData, - data: ['鍛ㄤ竴', '鍛ㄤ簩', '鍛ㄤ笁', '鍛ㄥ洓', '鍛ㄤ簲', '鍛ㄥ叚', '鍛ㄦ棩'], - axisLine: { - lineStyle: { - color: '#FFFFFF', - width: 1 - } - } - }, - yAxis: { - type: 'value', - axisLine: { - lineStyle: { - color: '#FFFFFF', - width: 1 - } - } - }, - series: [ - { - name: '閭欢钀ラ攢', - type: 'line', - stack: '鎬婚噺', - data: [120, 132, 101, 134, 90, 230, 210] - }, - { - name: '鑱旂洘骞垮憡', - type: 'line', - stack: '鎬婚噺', - data: [220, 182, 191, 234, 290, 330, 310] - }, - { - name: '瑙嗛骞垮憡', - type: 'line', - stack: '鎬婚噺', - data: [150, 232, 201, 154, 190, 330, 410] - }, - { - name: '鐩存帴璁块棶', - type: 'line', - stack: '鎬婚噺', - data: [320, 332, 301, 334, 390, 330, 320] - }, - { - name: '鎼滅储寮曟搸', - type: 'line', - stack: '鎬婚噺', - data: [820, 932, 901, 934, 1290, 1330, 1320] - } - ] - } - this.myChart.setOption(option) - }, - async echartsData () { - const addDays = dayjs().add(300, 'day') - const data = { - $tagCodeList: 'TJIP45.yyqAI90305,TJIP45.yyqAI90303,TJIP45.yyqFI_90310N,TJIP45.yyqAI90304,TJIP45.yyqAIR001', - $startTime: this.dayjs, - $endTime: addDays, - $step: 15 - } - const result = await mapApi.DataItems(data) - this.result = result.data - }, - // 鏁版嵁鐨勮姹� - requestEcharts () { - setInterval(async () => { - const addDays = dayjs().add(300, 'day') - const data = { - $tagCodeList: 'TJIP45.yyqAI90305,TJIP45.yyqAI90303,TJIP45.yyqFI_90310N,TJIP45.yyqAI90304,TJIP45.yyqAIR001', - $startTime: this.dayjs, - $endTime: addDays, - $step: 15 - } - const result = await mapApi.DataItems(data) - this.result = result.data - for (let i = 0; i < result.length; i++) { - // // console.log(result[i]) - - const seriesData = [] - const aseries = [] - // let nameData = '' - - seriesData.push(result[i].ReadTime) - aseries.push(result[i].TagValue) - // nameData = result[i].UnionTagCode - this.aseries = result[i].UnionTagCode - } - this.myChart.setOption({ - series: [{ - data: data - }] - }) - }, 3000) + days: dayjs(new Date()).format('YYYYMMDDHHmmss'), + data: [] } }, mounted () { this.$nextTick(() => { - this.requestEcharts() - this.drawChart() + this.upDateEcharts() }) + }, + methods: { + // 鍒濆鍖杄charts + upDateEcharts () { + this.myChart = this.$echarts.init(this.$refs.echarts) + // this.myChart.setOption(this.options) + // setInterval(this.echartsData, 1000) + function randomData () { + now = new Date(+now + oneDay) + value = value + Math.random() * 21 - 10 + return { + name: now.toString(), + value: [ + [now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'), + Math.round(value) + ] + } + } + + // this.data = [] + var now = +new Date(1997, 9, 3) + var oneDay = 24 * 3600 * 1000 + var value = Math.random() * 1000 + for (var i = 0; i < 1000; i++) { + this.data.push(randomData()) + } + const option = { + title: { + text: '鍔ㄦ�佹暟鎹� + 鏃堕棿鍧愭爣杞�' + }, + tooltip: { + trigger: 'axis', + formatter: function (params) { + params = params[0] + var date = new Date(params.name) + return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' : ' + params.value[1] + }, + axisPointer: { + animation: false + } + }, + xAxis: { + type: 'time', + splitLine: { + show: false + } + }, + yAxis: { + type: 'value', + boundaryGap: [0, '100%'], + splitLine: { + show: false + } + }, + series: [{ + name: '妯℃嫙鏁版嵁', + type: 'line', + showSymbol: false, + hoverAnimation: false, + data: this.data + }] + } + + setInterval(function () { + for (var i = 0; i < 5; i++) { + this.data.shift() + this.data.push(randomData()) + } + + // this.myChart.setOption({ + // series: [{ + // data: this.data + // }] + // }) + }, 1000) + this.myChart.setOption(option) + } } } </script> <style scoped lang="less"> -.Infomation { - margin-left: 10px; - height: 0.2rem; -} -.el-tag { - height: 25px; - width: 140px; - line-height: 25px; - margin-right: 10px; - font-size: 10px; - background-color: rgba(0, 255, 246, 0.14); - color: #00d0f9; - border: none; - padding: 0 15px; -} - -.form-echrts { - width: 100%; - height: 1rem; - border-top: 1px solid #396d83; - //margin: 10px 10px 10px 10px; - .el-dialog-div { - //height: 50vh!important; - overflow: auto; - //overflow: hidden; - } - - #echarts { - margin: 0; - padding: 0; - //height: 3rem; - //border: 1px solid #396d83; - //margin: 10px 10px 10px 10px; - } -} </style> -- Gitblit v1.8.0