Radar.vue 2.89 KB
<template>
  <div class='radar'>
    <div
      ref='radar'
      class='radar-canvas'
    ></div>
    <div class="radar-title">{{title}}</div>
  </div>
</template>

<script type='text/ecmascript-6'>
export default {
  name: 'Radar',
  data () {
    return {
      title: ''
    }
  },
  props: {
    listData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    isRowIndex: {
      type: Array,
      default: []
    },
    itemColor: {
      type: String,
      default: '#00e0b3'
    }
  },
  mounted () {

  },
  watch: {
    'listData' (n, o) {
      if (n) {
        this.draw()
      }
    }
  },
  methods: {
    draw () {
      this.title = this.listData.data[0].name
      let canvas = echarts.init(this.$refs.radar)
      let obj = this.listData
      let indicator = obj.indicator
      let data = obj.data
      data[0].value.forEach((e, i) => {
        indicator[i].value = e
        indicator[i].index = i
      })
      let options = {
        radar: {
          radius: '50%',
          splitNumber: 5,
          center: ['50%', '40%'],
          name: {
            formatter: (value, indicator) => {
              let row_column = true
              let val = `{a|${value}}\n{b|${indicator.value}}`
              this.isRowIndex.forEach(e => {
                if (e == indicator.index) val = `{a|${value}}\t{b|${indicator.value}}`
              })
              return val
            },
            rich: {
              a: {
                color: '#fff',
                fontSize: 16,
                align: 'center'
              },
              b: {
                color: '#fff',
                fontSize: 16,
                lineHeight: 25,
                align: 'right'
              },
            },
          },
          axisLine: false,
          splitLine: {
            lineStyle: {
              width: 3,
              color: 'rgba(45,153,186,0.2)'
            }
          },
          splitArea: false,
          indicator: indicator
        },
        series: [{
          type: 'radar',
          symbolSize: 0,
          areaStyle: {
            color: {
              type: 'radial',
              x: 0.5,
              y: 0.5,
              r: 0.8,
              colorStops: [{
                offset: 0, color: 'rgba(0,0,0,0)' // 0% 处的颜色
              }, {
                offset: 1, color: this.itemColor // 100% 处的颜色
              }],
              globalCoord: false
            },
          },
          lineStyle: {
            color: this.itemColor
          },
          data: data
        }],
      }
      canvas.setOption(options)
    }
  }
}
</script>

<style scoped lang='scss'>
.radar {
  width: 100%;
  height: 100%;
  position: relative;
  &-canvas {
    width: 100%;
    height: 100%;
  }
  &-title {
    position: absolute;
    left: 0;
    bottom: 20px;
    width: 100%;
    text-align: center;
    font-size: 24px;
    color: #8e99a6;
  }
}
</style>