派生自 wuyushui/SewerAndRainNetwork

chenzeping
2021-04-09 f84e5a87d3aeb665f4a84113e7e67533d2979faf
src/components/BaseNav/PublicBounced/GasComponents/Echarts.vue
@@ -4,7 +4,7 @@
<script>
import mapApi from '@/api/mapApi'
// import mapApi from '@/api/mapApi'
import 'dayjs/locale/es'
import dayjs from 'dayjs'
@@ -13,201 +13,95 @@
  data () {
    return {
      myChart: [],
      result: [],
      days: dayjs(new Date()).format('YYYYMMDDHHmmss'),
      value: '',
      seriesData: [],
      aseries: ''
      data: []
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.upDateEcharts()
    })
  },
  methods: {
    drawChart () {
    // 初始化echarts
    upDateEcharts () {
      this.myChart = this.$echarts.init(this.$refs.echarts)
      const option = {
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
        },
        grid: {
          containLabel: false
        },
        toolbox: {
          feature: {
            saveAsImage: {
              show: false
      // 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: 'category',
          boundaryGap: false,
          type: 'time',
          splitLine: {
            show: false
          },
          // data: this.seriesData,
          data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
          axisLine: {
            lineStyle: {
              color: '#FFFFFF',
              // width: 1
              show: false
            }
          }
        },
        yAxis: {
          type: 'value',
          boundaryGap: [0, '100%'],
          axisLine: {
            lineStyle: {
              color: '#FFFFFF',
              width: 1
            }
          splitLine: {
            show: false
          }
        },
        series: [
          {
        series: [{
            name: '模拟数据',
            type: 'line',
            // showSymbol: false,
            // hoverAnimation: false,
            data: this.seriesData
          },
          {
            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]
          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)
    },
    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
      for (let i = 0; i < result.length; i++) {
        //   // console.log(result[i])
        // const seriesData = []
        const aseries = []
        // let nameData = ''
        this.seriesData.push(result[i].ReadTime)
        aseries.push(result[i].TagValue)
        // nameData = result[i].UnionTagCode
        this.aseries = result[i].UnionTagCode
      }
      this.myChart.setOption({
        series: [{
          data: this.seriesData
        }]
      })
    },
    // 数据的请求
    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 = ''
          this.seriesData.push(result[i].ReadTime)
          aseries.push(result[i].TagValue)
          // nameData = result[i].UnionTagCode
          this.aseries = result[i].UnionTagCode
        }
        this.myChart.setOption({
          series: [{
            data: this.seriesData
          }]
        })
      }, 3000)
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.requestEcharts()
      this.drawChart()
      this.echartsData()
    })
  }
}
</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>