echarts 漏斗圖

1. vue按需引入漏斗圖

/**
 * echarts版本 4.9.0
 * main.js
 */
const echarts = require('echarts/lib/echarts')
require('echarts/lib/chart/funnel') // 漏斗
require('echarts/lib/component/title') // 圖表標(biāo)題
require('echarts/lib/component/dataZoom') // dataZoom組件

Vue.prototype.$echarts = echarts

2. 組件中使用

<template>
  <div class="funner-echart-container">
    <div ref="funnerEchart"></div>
  </div>
</template>

<script>
export default {
  name: 'FunnelEchart',
  data() {
    return {
      color: ['#9cbbfb', '#7da5fc', '#5b90fa', '#4077ec', '#2b67db'],
      echartData: [
        { value: 100, name: 'Show' },
        { value: 80, name: 'Click' },
        { value: 60, name: 'Visit' },
        { value: 40, name: 'Inquiry' },
        { value: 20, name: 'Order', labelLine: { show: false }}
      ]
    }
  },
  methods: {
    initOption() {
      return {
        color: this.color,
        series: [
          // 外部
          {
            ...this.handleSameOption(),
            silent: true, // 不處理鼠標(biāo)事件
            label: {
              position: 'rightBottom',
              color: '#000',
              lineHeight: 16,
              formatter: (params) => {
                return params.dataIndex === this.echartData.length - 1
                  ? ''
                  : `{name|開戶率} ${params.data.value}\n{name|提升率} 1`
              },
              rich: { // 自定義富文本樣式
                name: {
                  color: 'skyblue'
                }
              }
            },
            labelLine: { // 標(biāo)簽視覺引導(dǎo)線樣式
              length: 50,
              lineStyle: {
                color: '#eaeaea'
              }
            }
          },
          // 內(nèi)部
          {
            ...this.handleSameOption(),
            label: {
              position: 'inside'
            }
          }
        ]
      }
    },
    // 處理相同配置
    handleSameOption() {
      return {
        name: 'FunnelEcharts',
        type: 'funnel',
        top: '5%',
        left: '-10%',
        width: '90%',
        height: '90%',
        minSize: '20%', // 如果需要最小值的圖形并不是尖端三角,可通過設(shè)置該屬性實(shí)現(xiàn)
        maxSize: '60%',
        itemStyle: {
          borderWidth: 0 // 描邊線寬
        },
        data: this.echartData
      }
    }
  },
  mounted() {
    const myChart = this.$echarts.init(this.$refs.funnerEchart)
    myChart.setOption(this.initOption())
    window.onresize = function() {
      myChart.resize()
    }
  }
}
</script>

<style scoped lang="less">
  .funner-echart-container {
    > div {
      height: 280px;
    }
  }
</style>


3. 最終效果圖

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容