Order.vue 3.68 KB
<template>
  <div
    class='order-data'
    ref='data'
  >
  </div>
</template>

<script type='text/ecmascript-6'>
import map_code from '@p/map/mapId.js'
const lineColor = ['#f91e39', '#ffba34', '#2691ff', '#00c0c2']
export default {
  name: 'Order',
  data () {
    return {
    }
  },
  props: {
    list: {
      type: Array,
      default: []
    }
  },
  mounted () {

  },
  watch: {
    'list' (n, o) {
      if (n) {
        this.createdCanvas()
      }
    }
  },
  methods: {
    createdCanvas () {
      let arr = this.list
      let list = []
      let data = []
      arr.forEach(e => {
        data.push(e.value)
        for (const key in map_code) {
          if (map_code[key] == e.prov_code) {
            list.push({
              name: key
            })
          }
        }
      })
      arr.forEach((e, index) => {
        list[index].value = (e.value / arr[0].value).toFixed(2) * 100
      })
      let canvas = echarts.init(this.$refs.data)
      let options = {
        xAxis: [{
          type: 'value',
          min: 0,
          max: 100,
          gridIndex: 0,
          axisTick: { show: false, inside: false },
          axisLabel: { show: false },
          axisLine: {// Y轴轴线样式
            show: false,
          },
          splitLine: {
            show: false
          }
        },
        {
          gridIndex: 1,
          show: false,
        }],
        yAxis: [{
          type: 'category',
          gridIndex: 0,
          inverse: true,
          data: data,
          axisTick: { show: false },
          axisLabel: { show: false },
          axisLine: { show: false }
        },
        {
          gridIndex: 1,
          type: 'category',
          inverse: true,
          position: 'left',
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#ffffff',
              fontSize: 24,
              align: 'left'
            },
          },
          data: data
        }],
        grid: [{
          top: 30,
          bottom: 0,
          width: '180px',
          left: '165px',
          gridIndex: 0,
          containLabel: true,
        },
        {
          show: false,
          left: '395px',
          top: 30,
          bottom: 0,
          gridIndex: 1,
          width: '0%',
        },],
        series: [
          {
            type: 'bar',
            barWidth: '10',
            gridIndex: 0,
            itemStyle: {
              show: true,
              color: val => {
                return lineColor[val.dataIndex]
              },
              barBorderRadius: 4,
            },
            data: list
          },
          {
            name: 'border',
            type: 'bar',
            barWidth: '10',
            label: {
              color: '#ffffff',
              fontSize: 24,
              position: 'left',
              offset: [-38, 0],
              show: true,
              formatter: val => {
                let label = ''
                list.forEach((e, ind) => {
                  if (val.dataIndex == ind) label = `${ind + 1}\t\t\t${e.name}`
                })
                return label
              }
            },
            itemStyle: {
              normal: {
                barBorderRadius: 4,
                color: 'rgba(44, 145, 255, 0.1)' //rgba设置透明度0.14
              }
            },
            barGap: '-100%',
            z: 0,
            data: [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
          }
        ]
      }
      canvas.setOption(options)
    }
  }
}
</script>

<style scoped lang='scss'>
.order-data {
  width: 100%;
  height: 100%;
}
</style>