behaviordis.vue 3.62 KB
<template>
  <div>
    <div class="chart-header-box">
      <div class="header-title ">今日事件类型占比</div>
    </div>
    <div id="eventchart" class="eventchart"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      illtype: ""
    };
  },
  methods: {
    initchart(data) {
      var ydata = [];
      if(data.length > 0) {

        data.map(ele => {
          let obj = {
            name:ele.event_name,
            value:ele.total_num
          }
          ydata.push(obj)
        })
      }
      var color = [
        "#0069FF",
        "#3BB7FF",
        "#FF9630",
        "#FFC62E",
        "#87D14B",
        "#7460EE",
        "#f59a8f",
      ];
      var xdata = [
        "拥堵",
        "异常停车",
        "遗撒",
        "行人上路",
        "追尾",
        "其他",
      ];
      let maychart = this.$echarts.init(document.getElementById("eventchart"));
      let option = {
        color: color,
        legend: {
          orient: "vartical",
          x: "left",
          top: "center",
          left: "55%",
          bottom: "0%",
          data: xdata,
          itemWidth: 6,
          itemHeight: 8,
          itemGap: 10,
          /*formatter:function(name){
	      var oa = option.series[0].data;
	      var num = oa[0].value + oa[1].value + oa[2].value + oa[3].value+oa[4].value + oa[5].value + oa[6].value + oa[7].value+oa[8].value + oa[9].value ;
	      for(var i = 0; i < option.series[0].data.length; i++){
              if(name==oa[i].name){
              	return ' '+name + '    |    ' + oa[i].value + '    |    ' + (oa[i].value/num * 100).toFixed(2) + '%';
              }
	      }
	    }*/

          formatter: function(name) {
            return "" + name;
          }
        },
        series: [
          {
            type: "pie",
            clockwise: false, //饼图的扇区是否是顺时针排布
            minAngle: 2, //最小的扇区角度(0 ~ 360)
            radius: ["50%", "70%"],
            center: ["30%", "50%"],
            avoidLabelOverlap: false,
            itemStyle: {
              //图形样式
              normal: {
                borderColor: "#ffffff",
                borderWidth: 1
              }
            },
            label: {
              normal: {
                show: false,
                position: "center",
                formatter: "{text|{b}}\n{c} ({d}%)",
                rich: {
                  text: {
                    color: "#666",
                    fontSize: 14,
                    align: "center",
                    verticalAlign: "middle",
                    padding: 8
                  },
                  value: {
                    color: "#8693F3",
                    fontSize: 24,
                    align: "center",
                    verticalAlign: "middle"
                  }
                }
              },
              emphasis: {
                show: true,
                textStyle: {
                  fontSize: 14
                }
              }
            },
            data: ydata
          }
        ]
      };
      maychart.setOption(option);
    },
    getbehaviortype() {
     
    }
  },
  mounted() {
     this.$api.show.getBehaviorType().then(res => {
        this.initchart(res.list_data);
      })
  }
};
</script>

<style lang="stylus" scoped>
.chart-header-box {
  height: 3vh;
  overflow: hidden;
  font-size: 14px;
}
.header-title{
  line-height 3vh;
  padding-left 5px
}
.eventchart {
  height: 22vh;
  width: 20vw;
}

.header-label {
  font-size: 12px;
  line-height: 3vh;
  float: left;
}

.header-select {
  width: 4.5vw;
  margin: 0.2vh 0.5vw 0 0.2vw;
  float: left;
}
</style>