Vue Echarts 漏斗图(金字塔型)

Vue Echarts 漏斗图(金字塔型)

一般的漏斗图

<template>
  <div class="timeLineview">
    <div  style="height:400px" ref="categoryChart"></div>
  </div>
</template>

<script>
//调用echarts
import echarts from "echarts";
export default {
  components: {},
  name: "timeLine",
  props: {
    question: {}
  },
  data() {
    return {
    };
  },
  methods: {
    find() {
      this.chart = echarts.init(this.$refs.categoryChart);
      const option = {
    title: {
        text: '漏斗图',
        subtext: '纯属虚构'
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c}%"
    },
    toolbox: {
        feature: {
            dataView: {readOnly: false},
            restore: {},
            saveAsImage: {}
        }
    },
    legend: {
        data: ['展现','点击','访问','咨询','订单']
    },

    series: [
        {
            name:'漏斗图',
            type:'funnel',
            left: '10%',
            top: 60,
            bottom: 60,
            width: '80%',
            min: 0,
            max: 100,
            minSize: '0%',
            maxSize: '100%',
            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: '访问'},
                {value: 40, name: '咨询'},
                {value: 20, name: '订单'},
                {value: 80, name: '点击'},
                {value: 100, name: '展现'}
            ]
        }
    ]
};

      this.chart.setOption(option);
    }
  },
  mounted() {
    this.find();
  },
  created() {}
};
</script>

<style  lang="less" scoped>
</style>

在这里插入图片描述

把漏斗图改为金字塔图

只要在series中添加一句 sort: “ascending”,改变图形方向就可以了
在这里插入图片描述

自定义显示颜色

在series中添加itemStyle,存放你要改变的颜色数组(在其他图形中也适用)

<template>
  <div class="timeLineview">
    <div  style="height:400px" ref="categoryChart"></div>
  </div>
</template>

<script>
//调用echarts
import echarts from "echarts";
export default {
  components: {},
  name: "timeLine",
  props: {
    question: {}
  },
  data() {
    return {
    };
  },
  methods: {
    find() {
      this.chart = echarts.init(this.$refs.categoryChart);
      const option = {
    title: {
        text: '漏斗图',
        subtext: '纯属虚构'
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c}%"
    },
    toolbox: {
        feature: {
            dataView: {readOnly: false},
            restore: {},
            saveAsImage: {}
        }
    },
    legend: {
        data: ['展现','点击','访问','咨询','订单']
    },

    series: [
        {
            name:'漏斗图',
            type:'funnel',
            left: '10%',
            top: 60,
            bottom: 60,
            width: '80%',
            min: 0,
            max: 100,
            minSize: '0%',
            maxSize: '100%',
            gap: 2,
            label: {
                show: true,
                position: 'inside'
            },
            labelLine: {
                length: 10,
                lineStyle: {
                    width: 1,
                    type: 'solid'
                }
            },
         itemStyle: {
              borderColor: "#fff",
              borderWidth: 1,
              normal: {
                color: function(params) {
                  //自定义颜色
                  var colorList = [
                    "#FF4C4C",
                    "#FF6383",
                    "#FF9933",
                    "#FFC635",
                    "#31DC72",
                    "#39E8DE",
                    "#91FFE7",
                    "#91FAB9",
                    "#8572FF",
                    "#4578FF"
                  ];
                  return colorList[params.dataIndex];
                }
              }
            },
            emphasis: {
                label: {
                    fontSize: 20
                }
            },
            data: [
                {value: 60, name: '访问'},
                {value: 40, name: '咨询'},
                {value: 20, name: '订单'},
                {value: 80, name: '点击'},
                {value: 100, name: '展现'}
            ]
        }
    ]
};

      this.chart.setOption(option);
    }
  },
  mounted() {
    this.find();
  },
  created() {}
};
</script>

<style  lang="less" scoped>
</style>

在这里插入图片描述

修改内部显示数据

在series中添加label,设置你要修改的格式(在其他图形中也适用)

<template>
  <div class="timeLineview">
    <div  style="height:400px" ref="categoryChart"></div>
  </div>
</template>

<script>
//调用echarts
import echarts from "echarts";
export default {
  components: {},
  name: "timeLine",
  props: {
    question: {}
  },
  data() {
    return {
    };
  },
  methods: {
    find() {
      this.chart = echarts.init(this.$refs.categoryChart);
      const option = {
    title: {
        text: '漏斗图',
        subtext: '纯属虚构'
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c}%"
    },
    toolbox: {
        feature: {
            dataView: {readOnly: false},
            restore: {},
            saveAsImage: {}
        }
    },
    legend: {
        data: ['展现','点击','访问','咨询','订单']
    },

    series: [
        {
            name:'漏斗图',
            type:'funnel',
            left: '10%',
            top: 60,
            bottom: 60,
            width: '80%',
            min: 0,
            max: 100,
            minSize: '0%',
            maxSize: '100%',
            gap: 2,
              label: {
              normal: {
                position: "inside", // 标签的位置:'left'漏斗图的左侧)、'right'(右侧)、'inside'(内部) [ default: 'outside' ]
                formatter: "{a} -{b} : {c}", //按照需求显示对于的数据格式
                textStyle: {
                  color: "#fff"
                }
              }
            },
            labelLine: {
                length: 10,
                lineStyle: {
                    width: 1,
                    type: 'solid'
                }
            },
         itemStyle: {
              borderColor: "#fff",
              borderWidth: 1,
              normal: {
                color: function(params) {
                  //自定义颜色
                  var colorList = [
                    "#FF4C4C",
                    "#FF6383",
                    "#FF9933",
                    "#FFC635",
                    "#31DC72",
                    "#39E8DE",
                    "#91FFE7",
                    "#91FAB9",
                    "#8572FF",
                    "#4578FF"
                  ];
                  return colorList[params.dataIndex];
                }
              }
            },
            emphasis: {
                label: {
                    fontSize: 20
                }
            },
            data: [
                {value: 60, name: '访问'},
                {value: 40, name: '咨询'},
                {value: 20, name: '订单'},
                {value: 80, name: '点击'},
                {value: 100, name: '展现'}
            ]
        }
    ]
};

      this.chart.setOption(option);
    }
  },
  mounted() {
    this.find();
  },
  created() {}
};
</script>

<style  lang="less" scoped>
</style>

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值