illegaltrend.vue 6.47 KB
<template>
  <div>
    <div class="chart-header-box">
      <el-col :span="5" class="header-title">违法事件趋势</el-col>
        <span class="header-label">违法</span>
        <div class="header-select">
          <el-select v-model="illtype">
           <el-option
            v-for="item in illageList"
            :key="item.value"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
        </div>
        <span  class="header-label">事件</span>
        <div class="header-select">
          <el-select v-model="illtype">
           <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.code">
          </el-option>
        </el-select>
        </div>
        <span class="header-label">重点车辆</span>
        <div class="header-select">
          <el-select v-model="illtype">
           <el-option
            v-for="item in illageList"
            :key="item.value"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </div>
    </div>
    <div id="illtrendchart" class="illtrendchart"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      illtype:'',
      options:[],
      illageList: [],
    };
  },
  methods: {
    initchart(cdata) {
      let xData =  ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24"]
      let maychart = this.$echarts.init(document.getElementById("illtrendchart"));
      let option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        legend: {
          data: ["违法", "事件", "重点车辆"],
          align: "right",
          bottom: 0,
          textStyle: {
            color: "#666"
          },
          itemGap: 30,
          itemWidth: 30,
          itemHeight: 10
        },
        grid: {
          top:"10%",
          left: "3%",
          right: "10%",
          bottom: "10%",
          containLabel: true
        },
        xAxis: [
          {
            type: "category",
            data:xData,
            axisLine: {
              show: true,
              lineStyle: {
                color: "#D9D9D9",
                width: 1,
                type: "solid"
              }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: "#666666",
                fontSize: 14
              }
            }
          }
        ],
        yAxis: [
          {
            type: "value",
            splitNumber: 6,
            axisLabel: {
              formatter: "{value}",
              textStyle: {
                color: "#666",
                fontSize: 14
              }
            },
            axisTick: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "#D9D9D9",
                width:1,
                type: "solid"
              }
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: "#E5E5E5",
                width: 1,
                type: "solid"
              }
            }
          }
        ],
        series: [
          {
            name: "违法",
            type: "line",
            data: (function() {
              let d = []
              cdata.illegal.map(ele => {
                for(let i = 0; i < xData.length; i++) {
                  if(ele.hour == xData[i]){
                    d.push(ele.total_num)
                  } else {
                    d.push(0)
                  }
                }
              })
              return d;
            })(),
            itemStyle: {
              normal: {
                color: "#0069FF"
              }
            },
            lineStyle: {
              normal: {
                width: 1,
                shadowColor: "rgba(0,0,0,0.4)",
                shadowBlur: 10,
                shadowOffsetY: 10
              }
            }
          },
          {
            name: "事件",
            type: "line",
            data: (function() {
              let d = []
              cdata.event_type.map(ele => {
                for(let i = 0; i < xData.length; i++) {
                  if(ele.hour == xData[i]){
                    d.push(ele.total_num)
                  } else {
                    d.push(0)
                  }
                }
              })
              return d;
            })(),
            itemStyle: {
              normal: {
                color: "#3BB7FF"
              }
            },
            lineStyle: {
              normal: {
                width: 1,
                shadowColor: "rgba(0,0,0,0.4)",
                shadowBlur: 10,
                shadowOffsetY: 10
              }
            }
          },
          {
            name: "重点车辆",
            type: "line",
           data: (function() {
              let d = []
              cdata.key_vehicle.map(ele => {
                for(let i = 0; i < xData.length; i++) {
                  if(ele.hour == xData[i]){
                    d.push(ele.total_num)
                  } else {
                    d.push(0)
                  }
                }
              })
              return d;
            })(),
            itemStyle: {
              normal: {
                color: "#87D14B"
              }
            },
            lineStyle: {
              normal: {
                width: 1,
                shadowColor: "rgba(0,0,0,0.4)",
                shadowBlur: 10,
                shadowOffsetY: 10
              }
            }
          },
        ]
      };
     maychart.setOption(option)
    },
    getillageList(){
      this.illageList = JSON.parse(localStorage.getItem('违法类型')) ;
    },
    getTrafficHour(){
      this.$api.show.getTrafficHour().then(res => {
           this.initchart(res)
      })
    }
  },
  created(){
  },
  mounted() {
    this.getillageList()
    this.getTrafficHour()

    },
    
};
</script>

<style lang="stylus" scoped>
.chart-header-box{
  height 3vh
  overflow hidden
  font-size 14px
}
.header-title {
  line-height 3vh
}
.illtrendchart{
  height 22vh
  width 30vw
}
.header-label{
  font-size 12px
  line-height 3vh
  float left
}
.header-select{
  width 4.5vw
  margin .2vh .5vw 0 .2vw
  float left
}

</style>