Newer
Older
ganzhou-feidu / src / pages / ywts / shms / tcy / components / carsRate.vue
dutingting 22 days ago 6 KB 停车云完成
<!-- 近一月车场利用率 -->
<template>
  <div id="caseRate-linebar" class="container"/>
</template>

<script>
import * as echarts from 'echarts';
import { automaticCarousel } from './automaticCarousel'
import { getCarsRate } from '@/api/ywts/shms/tcy'
export default {
  name: 'CarsType',
  data() {
    return {
      isShow: true,
      myChart: null,
      height: '0',
      width: '0',
      chartSettings: {
        labelMap: { date: '时间' },
        metrics: [],
        dimension: ['date']
      },
      extend: {
        color: ['#CEDE0F'],
        legend: {
          show: false,
          textStyle: {
            color: '#cce9ff',
            fontWeight: 'bold'
          },
          lineStyle: {
            width: 10
          },
          data: ['车场利用率'],
        },
        dataZoom: [
          // 滑动条
          {
            xAxisIndex: 0, // 这里是从X轴的0刻度开始
            show: false, // 是否显示滑动条,不影响使用
            type: 'inside', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
            startValue: 0, // 开始位置。
            endValue: 1, // 一次性展示几个。(如果startValue设定为0,那么页面展示数就是endValue+1,比如此例页面展示2个)
          },
        ],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#092647',  // 修改背景颜色
              borderColor: '#404a59',      // 修改边框颜色
              borderWidth: 1,
              textStyle: {
                color: '#ffffff',          // 修改文本颜色
                fontSize: 12
              }
            }
          },
          textStyle: {
            align: 'left'  // 左对齐 tooltip 内容
          },
          formatter: function (params) {
            let result = params.map(function (item) {
                return '<div>' + item.marker + '车场利用率' + ': ' + item.value + '</div>';
            });
            result.pop()
            result.pop()
            return result.join(' ');
          }
        },
        grid: {
          left: '5%',
          right: '5%',
          bottom: '10%',
          top: '15%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          axisLine: {
            lineStyle: {
              color: '#cce9ff'
            }
          },
          axisLabel: {
            color: '#cce9ff'
          }
        },
        yAxis: [
          {
            name: '',
            type: 'value',
            axisLine: {
              lineStyle: {
                color: '#cce9ff'
              }
            },
            axisLabel: {
              color: '#cce9ff'
            },
            nameTextStyle: {
              color: '#cce9ff',
              fontSize: 14,
              verticalAlign: 'middle',
            },
            splitLine: {
              show: false,
              lineStyle: {
                color: ['#c8d0da'],
                type: 'dashed',
              },
            },
            axisTick: { show: false },
          },
        ],
        series: [
            {
            name: '上部圆',
            type: 'pictorialBar',
            silent: true,
            symbolSize: [20, 10],
            symbolOffset: [0, -4],
            symbolPosition: 'end',
            z: 12,
            label: {
                normal: {
                    show: true,
                    position: 'top',
                    fontSize: 15,
                    fontWeight: 'bold',
                    color: '#5BFCF4',
                },
            },
            color: '#5BFCF4',
        },
        {
            name: '底部圆',
            type: 'pictorialBar',
            silent: true,
            symbolSize: [20, 10],
            symbolOffset: [0, 4],
            z: 12,
            color: '#5BFCF4',
        },
        {
            name: '车场利用率',
            type: 'bar',
            barWidth: '20',
            barGap: '10%', // Make series be overlap
            barCateGoryGap: '10%',
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
                        {
                            offset: 0,
                            color: 'rgba(210,210,210,0.3)',
                        },
                        {
                            offset: 1,
                            color: '#5BFCF4',
                        },
                    ]),
                    opacity: 0.8,
                },
            },
        },
        ]
      },
      chartData: {
        columns: [],
        rows: []
      }
    }
  },
  mounted() {
    this.myChart = echarts.init(document.getElementById('caseRate-linebar'))
    this.height = document.getElementById('caseRate-linebar').clientHeight - 40 + 'px'
    this.width = document.getElementById('caseRate-linebar').clientWidth - 10 + 'px'
    const that = this
    window.addEventListener('resize', function() {
      if(!document.getElementById('caseRate-linebar')) {
        return
      }
      that.reload()
    })

  },

  methods: {
    async reload() {
      this.isShow = false
      await this.$nextTick()
      this.height = document.getElementById('caseRate-linebar').clientHeight - 10 + 'px'
      this.width = document.getElementById('caseRate-linebar').clientWidth - 10 + 'px'
      this.isShow = true
      automaticCarousel(this.extend, this.myChart, 3000, 7)
    },
    // 获取数据
    fetchData(id) {
      getCarsRate({id}).then(response => {
        if (response.code === 200) {
          const res = response.data.value.slice(0, 31)
          this.extend.series[0].data = res.map(item => item.rate)
          this.extend.series[1].data = res.map(item => item.rate)
          this.extend.series[2].data = res.map(item => item.rate)
          this.extend.xAxis.data = res.map(item => item.date)
          automaticCarousel(this.extend, this.myChart, 3000, 7)
          this.myChart.setOption(this.extend, true)
        }
      })
      // console.log('近1月车场利用率初始化');
      // this.extend.series[0].data = [20, 80, 100, 40, 34, 90, 60, 20, 80, 100, 40, 34]
      // this.extend.series[1].data = [20, 80, 100, 40, 34, 90, 60, 20, 80, 100, 40, 34]
      // this.extend.series[2].data = [20, 80, 100, 40, 34, 90, 60, 20, 80, 100, 40, 34]
      // this.extend.xAxis.data = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
      // automaticCarousel(this.extend, this.myChart, 3000, 5)
      // this.myChart.setOption(this.extend, true)

    }
  }
}
</script>
<style lang="scss" scoped>
.container{
  position:relative;
  width: 100%;
  height:100%;
}
</style>