FunnelChart.vue 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<!-- 漏斗图 -->
<template>
  <div
      :id="id"
      :class="className"
      :style="{height, width}"
  />
</template>

<script setup lang="ts">
11
import {nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted} from "vue";
12
import {init, EChartsOption} from 'echarts'
13
import resize from '@/utils/resize'
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

const props = defineProps({
  id: {
    type: String,
    default: 'funnelChart'
  },
  className: {
    type: String,
    default: ''
  },
  width: {
    type: String,
    default: '200px',
    required: true
  },
  height: {
    type: String,
    default: '200px',
    required: true
  }
})

36 37 38 39 40 41 42 43
const {
  mounted,
  chart,
  beforeDestroy,
  activated,
  deactivated
} = resize()

44
function initChart() {
45
  const funnelChart = init(document.getElementById(props.id) as HTMLDivElement)
46

47
  funnelChart.setOption({
48 49 50 51 52 53 54 55 56
    title: {
      show: true,
      text: '订单线索转化漏斗图',
      x: 'center',
      padding: 15,
      textStyle: {
        fontSize: 18,
        fontStyle: 'normal',
        fontWeight: 'bold',
57
        color:'#337ecc'
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
      }
    },
    grid: {
      left: '2%',
      right: '2%',
      bottom: '10%',
      containLabel: true
    },
    legend: {
      x: 'center',
      y: 'bottom',
      data: ['Show', 'Click', 'Visit', 'Inquiry', 'Order']
    },

    series: [
      {
        name: 'Funnel',
        type: 'funnel',
        left: '20%',
        top: 60,
        bottom: 60,
        width: '60%',
        min: 0,
        max: 100,
        minSize: '0%',
        maxSize: '100%',
        sort: 'descending',
        gap: 2,
        label: {
          show: true,
          position: 'inside'
        },
        labelLine: {
          length: 10,
          lineStyle: {
            width: 1,
            type: 'solid'
          }
        },
        itemStyle: {
          borderColor: '#fff',
          borderWidth: 1
        },
        emphasis: {
          label: {
            fontSize: 20
          }
        },
        data: [
          { value: 60, name: 'Visit' },
          { value: 40, name: 'Inquiry' },
          { value: 20, name: 'Order' },
          { value: 80, name: 'Click' },
          { value: 100, name: 'Show' }
        ]
      }
    ]
115 116
  } as EChartsOption)
  chart.value = funnelChart
117 118
}

119 120 121 122 123 124 125 126 127 128 129 130
onBeforeUnmount(() => {
  beforeDestroy()
})

onActivated(() => {
  activated()
})

onDeactivated(() => {
  deactivated()
})

131
onMounted(() => {
132
  mounted()
133 134 135 136
  nextTick(() => {
    initChart()
  })
})
137

138 139 140 141 142
</script>

<style lang="scss" scoped>

</style>