funnel.vue 2.21 KB
Newer Older
乐宝呗666's avatar
乐宝呗666 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<template>
    <div :id="idstr"></div>
</template>

<script>
export default {
  data () {
    return {
      dataObj: {},
      option: {},
      chart: null,
      clickNum: [1, 1, 1, 1, 1]
    }
  },
  props: ['message', 'idstr'],
  mounted () {
    this.drawLine()
  },
  methods: {
    drawLine () {
21
      const vm = this
乐宝呗666's avatar
乐宝呗666 committed
22
      // 基于准备好的dom,初始化echarts实例
23
      vm.chart = this.$echarts.init(document.getElementById(vm.idstr))
乐宝呗666's avatar
乐宝呗666 committed
24 25 26
      // 清空图表
      vm.chart.clear()
      vm.option = {
27
        color: ['#30DDF4', '#E23AA2', '#F5A623', '#D6FFBA'],
乐宝呗666's avatar
乐宝呗666 committed
28 29 30
        tooltip: {
          transitionDuration: 0,
          trigger: 'item',
31
          formatter: '{b} : {c}' // a对应系列名称,b对应数据项名称,c对应数据项值
乐宝呗666's avatar
乐宝呗666 committed
32 33 34
        },
        legend: {
          textStyle: {
35
            color: '#fff' // 图例文字颜色
乐宝呗666's avatar
乐宝呗666 committed
36
          },
37 38 39 40
          orient: 'vertical',
          left: 20,
          bottom: 10,
          data: vm.message.legend
乐宝呗666's avatar
乐宝呗666 committed
41 42 43 44 45 46
        },

        series: [
          {
            name: '漏斗图',
            type: 'funnel',
47 48 49
            left: '30%',
            top: 40,
            bottom: 20,
乐宝呗666's avatar
乐宝呗666 committed
50
            width: '80%',
51 52
            minSize: '10%',
            maxSize: '70%',
乐宝呗666's avatar
乐宝呗666 committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
            sort: 'descending',
            gap: 2,
            label: {
              show: true,
              position: 'inside',
              formatter: '{c}', // 展示数值
              borderRadius: ['30', '30', '30', '30']
            },
            labelLine: {
              length: 10,
              lineStyle: {
                width: 1,
                type: 'solid'
              }
            },
            itemStyle: {
              borderColor: '#fff',
              borderWidth: 1
            },
72
            data: vm.message.data
乐宝呗666's avatar
乐宝呗666 committed
73 74 75 76 77 78 79 80 81 82
          }
        ]
      }
      vm.drawBar()
      // window.addEventListener("resize",()=>{
      //     chart.resize();
      // });
    },
    drawBar () {
      // 绘制图表
83
      const vm = this
乐宝呗666's avatar
乐宝呗666 committed
84 85 86 87
      vm.chart.setOption(vm.option)
    }
  },
  watch: {
乐宝呗666's avatar
乐宝呗666 committed
88 89 90 91 92 93 94 95
    message: {
      handler () {
        const vm = this
        setTimeout(function () {
          vm.drawLine()
        }, 0)
      },
      deep: true
乐宝呗666's avatar
乐宝呗666 committed
96 97 98 99 100
    }
  }
}
</script>

101
<style lang="scss" scoped>
乐宝呗666's avatar
乐宝呗666 committed
102 103

</style>