funnelChart.vue 9.32 KB
<template>
  <div style="position:relative;">
    <basic ref="basic" :chartId="chartId" :chartData="chartData"></basic>
  </div>
</template>
<script>
import mixin from './mixin';
import { chartweather, weatherpng } from '../Charts/weather'
export default {
  mixins: [mixin],
  data() {
    return {

    }
  },
  methods: {
    /**
     * 预处理option参数
     * */
    preChartData(cdata) {
      /*if(!cdata||!cdata.data||!cdata.data[0]||cdata.data[0].value==0){
        cdata.series = [];
        cdata.noProcess = false;
      }*/
      return cdata;
    },
    /**
     * 处理option参数
     * */
    dealChartData(data) {
      var uploadedDataURL = "/asset/get/s/data-1576742942370-X6JMK0GY.png";
      var colors = ['#1cd389', '#668eff', '#ffc751', '#ff6e73', '#8683e6', '#9692ff'];
      var url = 'image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAARCAMAAACLgl7OAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAaVBMVEUAAADBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcEAAAD45xibAAAAInRSTlMAmT6WJYwSfBMGZAFHmEgtkBeCCW0KAlI1k5QeiA10A1tc7ah1owAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAB7SURBVCjPtZDZDoAgDAQXvA+8bwX1/3/SGKIBEd+cx07TdgtIiAF0/mygDvnAoYDr2b3nnjP8wOaDUG6J4ncfR9cdScpMzbJECZEXT1/kesyy0n1VPv6AulF908Kg6+9DWN/hjWGUfhpgYV5Ov8ywwgUhguODddtXvXIAjuUEs/70/t4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMTItMTZUMTU6MzM6MDkrMDg6MDCzL2BEAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTEyLTE2VDE1OjMzOjA5KzA4OjAwwnLY+AAAAABJRU5ErkJggg==';
      if (!data || JSON.stringify(data) === "{}"||data.data.length==0) {
        return false;
      }
      let chartdata = data.data.sort((a, b) => b.value - a.value);
      let graphic = [];
      let halfW = this.$refs.basic.$el.offsetWidth/2;
      let partH = 400/chartdata.length;
      let nameList = JSON.parse(JSON.stringify(chartdata)).sort((a, b) => b.value - a.value);
      for (var i = 0; i < nameList.length; i++) {
        graphic.push({
          type: 'group',
          bounding: 'raw',
          left:0,
          top: partH*i,
          children: [{
              type: 'rect',
              left: 0,
              top: 0,
              shape: {
                width: halfW,
                height: partH
              },
              style: {
                fill: i%2?'#fff':'#F5F7F9'
              }
            },
            {
              type: 'text',
              left: 20,
              top: partH/3,
              style: {
                fill: '#000',
                font: 'normal 15px sans-serif',
                text: nameList[i].name
              }
            },
            {
              type: 'text',
              left: 20,
              top: partH/1.9,
              style: {
                fill: '#3F8AFA',
                font: 'normal 15px sans-serif',
                text: this.toThousands(nameList[i].value)+this.$t("format.perNum")
              }
            }
          ]
        })
      }
      chartdata.forEach((item,idx)=>{
        item.value1 = item.value;
        item.value = 1000-250*idx;
        return item ;
      })
      var option = {
        backgroundColor: "transparent",
        graphic,
        color: data.color || ["#6FA9FF", "#FF9C7F", "#66D5C6", "#FFD48A", "#FFA2C0"],
        grid: {
          left: 0,
          right: 0,
          top: 0,
          bottom: 0
        },
        tooltip: {
          formatter: params => {
            return `${params.name} ${params.data.value1 || ""}${
              params.data.value1 ? this.$t("format.perNum") : ""
            }`;
          }
        },
        series: [{
            top: 0,
            type: 'funnel',
            height: 400,
            gap: 0,
            //minSize: 80,
            left: '25%',
            width: '50%',
            label: {
              show: true,
              position: 'inside',
              fontSize: '15',
              formatter: function(d) {
                var ins = d.name + '{aa|}\n' //+ d.data.value;
                return ins
              },
              rich: {
                aa: {
                  padding: [8, 0, 6, 0],
                }
              }
            },
            data: chartdata
          },
          {
            top: 0,
            type: 'funnel',
            gap: 0,
            height: 400,
            //minSize: 80,
            left: '25%',
            width: '50%',
            color: '#000000',
            z: 2,
            label: {
              normal: {
                color: '#000000',
                position: 'rightTop',
                //backgroundColor: '#f6f7fc',
                //borderColor: '#f6f7fc',
                //borderWidth: 1,
                //borderRadius: 4,
                //padding: [11, 25, 11, 25],
                formatter: function(d) {
                  let index = d.dataIndex;
                  let len = chartdata.length;
                  let perc = index == 0 ? '' : (d.data.value1 * 100 / chartdata[index-1].value1).toFixed(2) + '%';
                  let pinfo = "";
                  if (perc) {
                    pinfo = '{gap|}{aa|} ' + chartdata[index-1].name + '->' + chartdata[index].name + ':';
                  }
                  var ins = pinfo + '{bb|' + (perc) + '}';
                  return ins
                },
                rich: {
                  gap:{
                    width: 50,
                  },
                  aa: {
                    width: 50,
                    height: 320 / chartdata.length,
                    backgroundColor: {
                      image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHwAAACdCAYAAAB2BhyZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmV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73nx2YxOO0kX1to0qo1/QAmexreRk08jXHxer0+bLc2N2gj6kFoTd+brfyi9H+snr5eOp6enod1uh4ODg7hBxNKLJGoq6clxf6RH11lten39nHZkfd171x9/ftpnYP2/16cNofuukVmULWb4d40F4+PBLGPELK9h/b8F39raiqIfHR3FqhrncJGxUfktE3pLpSP1dZWHSRmvi2jnqFzoorpG6t/11pA+hPqNyrr6uN4zvT6V/HEypCOVq/r7sX629Ql5V4n3KmYkMuq3Evjq6qrq6Z1Opyr174UuKsKm4+TkBMr2C+bwvz9fVbq/7hT9MiJ9Yf7RjCd+geDSfLxMqDyPXHY5nvEqKaDU3y/4+3+cIeMl/KyGjPjhgqeMl9GS43uvx4vkIPjviQ9/H64yr+xORE5wRS5QNOf4+BjlcxM8vH7Hmly9Ri/1df271WoheI6C17Fqmrlf5z0Ez1DwSRsBwRGcQHBibvFHgAEA24Jfsudt6NAAAAAASUVORK5CYII='
                    }
                  },
                  bb: {
                    color: '#333',
                    fontSize: '14',
                  }
                }
              }
            },
            labelLine: {
              show: false
            },
            data: chartdata
          }
        ]
      };
      if(data.data.length==0)option.series=[];
      if (data.otherConf) {
        option.series.lineStyle = data.otherConf.lineStyle || '';
        option.series.top = data.otherConf.top || ''
      }

      return option;
    }
  },
  created() {

  }
}

</script>
<style scoped>
</style>